From 503385309b47540416bfecea829e528b168830b2 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Sun, 7 Oct 2007 14:34:53 +0200 Subject: [PATCH] Change playlist to use Esperanza's playlistmodel --- XMMSSocket.cpp | 29 - XMMSSocket.h | 20 - XmmsQT4.h | 33 -- config.pri | 2 + lib/TODO | 2 + lib/debug.h | 28 + lib/lib.pro | 35 ++ lib/playlistmodel.cpp | 516 ++++++++++++++++++ lib/playlistmodel.h | 147 +++++ lib/xclient.cpp | 210 +++++++ lib/xclient.h | 110 ++++ lib/xclientcache.cpp | 167 ++++++ lib/xclientcache.h | 80 +++ XmmsQT4.cpp => lib/xmmsqt4.cpp | 19 +- lib/xmmsqt4.h | 50 ++ promoe.pro | 84 +-- BrowseDialog.cpp => src/BrowseDialog.cpp | 0 BrowseDialog.h => src/BrowseDialog.h | 0 BrowseModel.cpp => src/BrowseModel.cpp | 5 +- BrowseModel.h => src/BrowseModel.h | 0 Button.cpp => src/Button.cpp | 0 Button.h => src/Button.h | 0 ClutterBar.cpp => src/ClutterBar.cpp | 0 ClutterBar.h => src/ClutterBar.h | 0 Display.cpp => src/Display.cpp | 0 Display.h => src/Display.h | 0 Equalizer.cpp => src/Equalizer.cpp | 0 Equalizer.h => src/Equalizer.h | 0 FileDialog.cpp => src/FileDialog.cpp | 0 FileDialog.h => src/FileDialog.h | 0 MainDisplay.cpp => src/MainDisplay.cpp | 13 +- MainDisplay.h => src/MainDisplay.h | 2 +- MainWindow.cpp => src/MainWindow.cpp | 0 MainWindow.h => src/MainWindow.h | 2 +- MedialibItem.h => src/MedialibItem.h | 0 .../MedialibTreeModel.cpp | 0 .../MedialibTreeModel.h | 0 MedialibView.cpp => src/MedialibView.cpp | 0 MedialibView.h => src/MedialibView.h | 1 - MedialibWindow.cpp => src/MedialibWindow.cpp | 0 MedialibWindow.h => src/MedialibWindow.h | 0 NumberDisplay.cpp => src/NumberDisplay.cpp | 3 +- NumberDisplay.h => src/NumberDisplay.h | 0 PixWidget.cpp => src/PixWidget.cpp | 0 PixWidget.h => src/PixWidget.h | 0 PlayStatus.cpp => src/PlayStatus.cpp | 0 PlayStatus.h => src/PlayStatus.h | 0 Playlist.cpp => src/Playlist.cpp | 267 +++++---- Playlist.h => src/Playlist.h | 81 ++- PlaylistList.cpp => src/PlaylistList.cpp | 0 PlaylistList.h => src/PlaylistList.h | 6 + PlaylistMenu.cpp => src/PlaylistMenu.cpp | 0 PlaylistMenu.h => src/PlaylistMenu.h | 0 PlaylistShade.cpp => src/PlaylistShade.cpp | 0 PlaylistShade.h => src/PlaylistShade.h | 0 src/PlaylistView.cpp | 221 ++++++++ src/PlaylistView.h | 57 ++ PosBar.cpp => src/PosBar.cpp | 0 PosBar.h => src/PosBar.h | 0 ServerBrowser.cpp => src/ServerBrowser.cpp | 0 ServerBrowser.h => src/ServerBrowser.h | 0 SettingsWindow.cpp => src/SettingsWindow.cpp | 0 SettingsWindow.h => src/SettingsWindow.h | 0 ShadedDisplay.cpp => src/ShadedDisplay.cpp | 9 +- ShadedDisplay.h => src/ShadedDisplay.h | 2 +- Skin.cpp => src/Skin.cpp | 4 +- Skin.h => src/Skin.h | 0 SkinChooser.cpp => src/SkinChooser.cpp | 0 SkinChooser.h => src/SkinChooser.h | 0 .../SmallNumberDisplay.cpp | 0 .../SmallNumberDisplay.h | 0 StereoMono.cpp => src/StereoMono.cpp | 0 StereoMono.h => src/StereoMono.h | 0 TextBar.cpp => src/TextBar.cpp | 3 +- TextBar.h => src/TextBar.h | 0 TimeDisplay.cpp => src/TimeDisplay.cpp | 3 +- TimeDisplay.h => src/TimeDisplay.h | 0 TitleBar.cpp => src/TitleBar.cpp | 0 TitleBar.h => src/TitleBar.h | 0 VolumeSlider.cpp => src/VolumeSlider.cpp | 0 VolumeSlider.h => src/VolumeSlider.h | 0 XMMSHandler.cpp => src/XMMSHandler.cpp | 102 ++-- XMMSHandler.h => src/XMMSHandler.h | 20 +- avahi.prf => src/avahi.prf | 0 icon.png => src/icon.png | Bin noalbum.png => src/noalbum.png | Bin noartist.png => src/noartist.png | Bin nocover.png => src/nocover.png | Bin nosong.png => src/nosong.png | Bin promoe.qrc => src/promoe.qrc | 0 qtmd5.cpp => src/qtmd5.cpp | 0 qtmd5.h => src/qtmd5.h | 0 src/src.pro | 89 +++ .../xmmsclient_methods.h | 0 .../xmmsclient_promoe.cpp | 0 .../xmmsclient_promoe.h | 0 96 files changed, 2010 insertions(+), 412 deletions(-) delete mode 100644 XMMSSocket.cpp delete mode 100644 XMMSSocket.h delete mode 100644 XmmsQT4.h create mode 100644 config.pri create mode 100644 lib/TODO create mode 100644 lib/debug.h create mode 100644 lib/lib.pro create mode 100644 lib/playlistmodel.cpp create mode 100644 lib/playlistmodel.h create mode 100644 lib/xclient.cpp create mode 100644 lib/xclient.h create mode 100644 lib/xclientcache.cpp create mode 100644 lib/xclientcache.h rename XmmsQT4.cpp => lib/xmmsqt4.cpp (69%) create mode 100644 lib/xmmsqt4.h rename BrowseDialog.cpp => src/BrowseDialog.cpp (100%) rename BrowseDialog.h => src/BrowseDialog.h (100%) rename BrowseModel.cpp => src/BrowseModel.cpp (96%) rename BrowseModel.h => src/BrowseModel.h (100%) rename Button.cpp => src/Button.cpp (100%) rename Button.h => src/Button.h (100%) rename ClutterBar.cpp => src/ClutterBar.cpp (100%) rename ClutterBar.h => src/ClutterBar.h (100%) rename Display.cpp => src/Display.cpp (100%) rename Display.h => src/Display.h (100%) rename Equalizer.cpp => src/Equalizer.cpp (100%) rename Equalizer.h => src/Equalizer.h (100%) rename FileDialog.cpp => src/FileDialog.cpp (100%) rename FileDialog.h => src/FileDialog.h (100%) rename MainDisplay.cpp => src/MainDisplay.cpp (95%) rename MainDisplay.h => src/MainDisplay.h (98%) rename MainWindow.cpp => src/MainWindow.cpp (100%) rename MainWindow.h => src/MainWindow.h (98%) rename MedialibItem.h => src/MedialibItem.h (100%) rename MedialibTreeModel.cpp => src/MedialibTreeModel.cpp (100%) rename MedialibTreeModel.h => src/MedialibTreeModel.h (100%) rename MedialibView.cpp => src/MedialibView.cpp (100%) rename MedialibView.h => src/MedialibView.h (89%) rename MedialibWindow.cpp => src/MedialibWindow.cpp (100%) rename MedialibWindow.h => src/MedialibWindow.h (100%) rename NumberDisplay.cpp => src/NumberDisplay.cpp (93%) rename NumberDisplay.h => src/NumberDisplay.h (100%) rename PixWidget.cpp => src/PixWidget.cpp (100%) rename PixWidget.h => src/PixWidget.h (100%) rename PlayStatus.cpp => src/PlayStatus.cpp (100%) rename PlayStatus.h => src/PlayStatus.h (100%) rename Playlist.cpp => src/Playlist.cpp (76%) rename Playlist.h => src/Playlist.h (72%) rename PlaylistList.cpp => src/PlaylistList.cpp (100%) rename PlaylistList.h => src/PlaylistList.h (94%) rename PlaylistMenu.cpp => src/PlaylistMenu.cpp (100%) rename PlaylistMenu.h => src/PlaylistMenu.h (100%) rename PlaylistShade.cpp => src/PlaylistShade.cpp (100%) rename PlaylistShade.h => src/PlaylistShade.h (100%) create mode 100644 src/PlaylistView.cpp create mode 100644 src/PlaylistView.h rename PosBar.cpp => src/PosBar.cpp (100%) rename PosBar.h => src/PosBar.h (100%) rename ServerBrowser.cpp => src/ServerBrowser.cpp (100%) rename ServerBrowser.h => src/ServerBrowser.h (100%) rename SettingsWindow.cpp => src/SettingsWindow.cpp (100%) rename SettingsWindow.h => src/SettingsWindow.h (100%) rename ShadedDisplay.cpp => src/ShadedDisplay.cpp (92%) rename ShadedDisplay.h => src/ShadedDisplay.h (94%) rename Skin.cpp => src/Skin.cpp (99%) rename Skin.h => src/Skin.h (100%) rename SkinChooser.cpp => src/SkinChooser.cpp (100%) rename SkinChooser.h => src/SkinChooser.h (100%) rename SmallNumberDisplay.cpp => src/SmallNumberDisplay.cpp (100%) rename SmallNumberDisplay.h => src/SmallNumberDisplay.h (100%) rename StereoMono.cpp => src/StereoMono.cpp (100%) rename StereoMono.h => src/StereoMono.h (100%) rename TextBar.cpp => src/TextBar.cpp (97%) rename TextBar.h => src/TextBar.h (100%) rename TimeDisplay.cpp => src/TimeDisplay.cpp (96%) rename TimeDisplay.h => src/TimeDisplay.h (100%) rename TitleBar.cpp => src/TitleBar.cpp (100%) rename TitleBar.h => src/TitleBar.h (100%) rename VolumeSlider.cpp => src/VolumeSlider.cpp (100%) rename VolumeSlider.h => src/VolumeSlider.h (100%) rename XMMSHandler.cpp => src/XMMSHandler.cpp (67%) rename XMMSHandler.h => src/XMMSHandler.h (85%) rename avahi.prf => src/avahi.prf (100%) rename icon.png => src/icon.png (100%) rename noalbum.png => src/noalbum.png (100%) rename noartist.png => src/noartist.png (100%) rename nocover.png => src/nocover.png (100%) rename nosong.png => src/nosong.png (100%) rename promoe.qrc => src/promoe.qrc (100%) rename qtmd5.cpp => src/qtmd5.cpp (100%) rename qtmd5.h => src/qtmd5.h (100%) create mode 100644 src/src.pro rename xmmsclient_methods.h => src/xmmsclient_methods.h (100%) rename xmmsclient_promoe.cpp => src/xmmsclient_promoe.cpp (100%) rename xmmsclient_promoe.h => src/xmmsclient_promoe.h (100%) diff --git a/XMMSSocket.cpp b/XMMSSocket.cpp deleted file mode 100644 index fcb3e90..0000000 --- a/XMMSSocket.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#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 deleted file mode 100644 index 05a3327..0000000 --- a/XMMSSocket.h +++ /dev/null @@ -1,20 +0,0 @@ -#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/XmmsQT4.h b/XmmsQT4.h deleted file mode 100644 index 4b2339d..0000000 --- a/XmmsQT4.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __XMMSQT4_H__ -#define __XMMSQT4_H__ - -#include - -#include -#include -#include - -class XmmsQT4 : public QObject, public Xmms::MainloopInterface -{ - Q_OBJECT - public: - XmmsQT4(xmmsc_connection_t *xmmsc); - ~XmmsQT4(); - - void run (); - - void ToggleWrite(bool toggle); - xmmsc_connection_t *GetXmmsConnection(); - - public slots: - void OnRead (); - void OnWrite (); - - private: - int m_fd; - QSocketNotifier *m_rsock; - QSocketNotifier *m_wsock; - xmmsc_connection_t *m_xmmsc; -}; - -#endif diff --git a/config.pri b/config.pri new file mode 100644 index 0000000..58a736d --- /dev/null +++ b/config.pri @@ -0,0 +1,2 @@ +DEPENDPATH += $PWD/src $PWD/lib +INCLUDEPATH += $$PWD/src $$PWD/lib diff --git a/lib/TODO b/lib/TODO new file mode 100644 index 0000000..464f267 --- /dev/null +++ b/lib/TODO @@ -0,0 +1,2 @@ +Contains a copy of some of Esperanzas src/lib/ directory +Will have to be removed as soon as those files become a seperate lib diff --git a/lib/debug.h b/lib/debug.h new file mode 100644 index 0000000..d31ec50 --- /dev/null +++ b/lib/debug.h @@ -0,0 +1,28 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +// Usage: include it and then just do a DBGOUT("bla foo bar " << variable << " is awesome."); +// while in debug mode, it will all be print to console. In release mode, DBGOUT does nothing + +#ifndef __DEBUG_H__ +# define __DEBUG_H__ +# ifdef _DEBUG +# include +# define DBGOUT(a) qDebug () << QString(__FILE__ ":%1").arg(__LINE__) << "[" << __func__ << "] -" << a +# else +# define DBGOUT(a) +# endif +#endif diff --git a/lib/lib.pro b/lib/lib.pro new file mode 100644 index 0000000..480ec93 --- /dev/null +++ b/lib/lib.pro @@ -0,0 +1,35 @@ +TEMPLATE = lib +CONFIG += static +include (../config.pri) + +SOURCES += xclient.cpp \ + xclientcache.cpp \ + playlistmodel.cpp \ + xmmsqt4.cpp + + +HEADERS += xclient.h \ + xclientcache.h \ + playlistmodel.h \ + xmmsqt4.h \ + debug.h + + + +;RESOURCES = promoe.qrc +;macx:RC_FILE = promoe.icns +;macx:INCLUDEPATH = /sw/include + +QT += network +;macx:QTPLUGIN += qjpeg +QMAKE_LFLAGS += -L$$[QT_INSTALL_PLUGINS]/imageformats + +CONFIG += link_pkgconfig + +QMAKE_CXXFLAGS += -g +;CONFIG += debug warn_on +QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter +PKGCONFIG += xmms2-client xmms2-client-cpp + +;CONFIG += avahi + diff --git a/lib/playlistmodel.cpp b/lib/playlistmodel.cpp new file mode 100644 index 0000000..42df036 --- /dev/null +++ b/lib/playlistmodel.cpp @@ -0,0 +1,516 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "playlistmodel.h" + +PlaylistModel::PlaylistModel (QObject *parent, XClient *client, const QString &name) : QAbstractItemModel (parent) +{ +// m_columns.append ("#"); + m_columns.append ("Artist"); + m_columns.append ("Title"); + +// m_colfallback.append (""); + m_colfallback.append (""); + m_colfallback.append ("url"); + + m_cached_size.append (QSize ()); + m_cached_size.append (QSize ()); + m_cached_size.append (QSize ()); + + connect (client, SIGNAL(gotConnection (XClient *)), this, SLOT (got_connection (XClient *))); + connect (client->cache (), SIGNAL(entryChanged (uint32_t)), this, SLOT (entry_changed (uint32_t))); + + if (name == QLatin1String ("_active")) { + m_isactive = true; + } + + m_name = name; + + if (client->isConnected ()) { + got_connection (client); + } +} + +void +PlaylistModel::set_playlist (const QString &name) +{ + if (name == QLatin1String ("_active")) { + m_isactive = true; + m_client->playlist ()->currentActive () (Xmms::bind (&PlaylistModel::handle_current_pls, this)); + } else { + m_isactive = false; + } + m_name = name; + m_client->playlist ()->listEntries (XClient::qToStd (name)) (Xmms::bind (&PlaylistModel::handle_list, this)); +} + +bool +PlaylistModel::handle_current_pls (const std::string &name) +{ + if (m_name == QLatin1String ("_active")) { + m_name = XClient::stdToQ (name); + } + + return true; +} + +void +PlaylistModel::got_connection (XClient *client) +{ + if (m_isactive) { + client->playlist ()->currentActive () (Xmms::bind (&PlaylistModel::handle_current_pls, this)); + } + + client->playlist ()->listEntries (XClient::qToStd (m_name)) (Xmms::bind (&PlaylistModel::handle_list, this)); + client->playlist ()->currentPos () (Xmms::bind (&PlaylistModel::handle_update_pos, this)); + + client->playlist ()->broadcastChanged () (Xmms::bind (&PlaylistModel::handle_change, this)); + client->playlist ()->broadcastCurrentPos () (Xmms::bind (&PlaylistModel::handle_update_pos, this)); + + client->playlist ()->broadcastLoaded () (Xmms::bind (&PlaylistModel::handle_pls_loaded, this)); + + m_client = client; +} + +bool +PlaylistModel::handle_pls_loaded (const std::string &name) +{ + if (m_isactive) { + m_client->playlist ()->listEntries (name) + (Xmms::bind (&PlaylistModel::handle_list, this)); + m_name = XClient::stdToQ (name); + } + + return true; +} + +bool +PlaylistModel::handle_update_pos (const uint32_t &pos) +{ + m_current_pos = pos; + emit dataChanged(index (pos, 0), index (pos, m_columns.size ())); + return true; +} + +QList +PlaylistModel::columns () const +{ + return m_columns; +} + +void +PlaylistModel::setColumns (const QList &new_columns) +{ + m_columns = new_columns; + reset (); +} + +void +PlaylistModel::setColumnFallback (const QList &new_columns) +{ + m_colfallback = new_columns; + reset (); +} + +bool +PlaylistModel::handle_change (const Xmms::Dict &chg) +{ + int32_t change = chg.get ("type"); + int32_t pos = 0, npos = 0; + uint32_t id = 0; + QString s; + + if (chg.contains ("position")) { + pos = chg.get ("position"); + } + + if (chg.contains ("id")) { + id = chg.get ("id"); + } + + if (chg.contains ("name")) { + s = XClient::stdToQ (chg.get ("name")); + } + + if (s != m_name) { + return true; + } + + QModelIndex idx = QModelIndex (); + + switch (change) { + case XMMS_PLAYLIST_CHANGED_ADD: + beginInsertRows (idx, pos, pos); + m_plist.append (id); + endInsertRows (); + break; + case XMMS_PLAYLIST_CHANGED_INSERT: + beginInsertRows (idx, pos, pos); + m_plist.insert (pos, id); + endInsertRows (); + break; + case XMMS_PLAYLIST_CHANGED_MOVE: + npos = chg.get ("newposition"); + + beginRemoveRows (idx, pos, pos); + m_plist.removeAt (pos); + endRemoveRows (); + + beginInsertRows (idx, npos, npos); + m_plist.insert (npos, id); + endInsertRows (); + + if (pos < npos && pos) + pos --; + + emit entryMoved (index (pos, 0), index (npos, 0)); + + break; + case XMMS_PLAYLIST_CHANGED_REMOVE: + m_client->cache ()->invalidate (m_plist[pos]); + beginRemoveRows (idx, pos, pos); + m_plist.removeAt (pos); + endRemoveRows (); + break; + case XMMS_PLAYLIST_CHANGED_SHUFFLE: + case XMMS_PLAYLIST_CHANGED_SORT: + case XMMS_PLAYLIST_CHANGED_CLEAR: + m_client->cache ()->invalidate_all (); + m_client->playlist ()->listEntries () (Xmms::bind (&PlaylistModel::handle_list, this)); + break; + } + + return true; +} + +bool +PlaylistModel::handle_list (const Xmms::List< unsigned int > &list) +{ + beginRemoveRows (QModelIndex (), 0, m_plist.size ()); + m_plist.clear (); + endRemoveRows (); + + int i = 0; + for (list.first (); list.isValid (); ++list) { + i ++; + } + beginInsertRows (QModelIndex (), 0, i); + for (list.first (); list.isValid (); ++list) { + m_plist.append (*list); + } + + endInsertRows (); + + return true; +} + +QModelIndexList +PlaylistModel::get_idxlist_by_id (uint32_t id) +{ + QModelIndexList ret; + + QList l = getPosById (id); + for (int i = 0; i < l.count (); i++) { + ret.append (index (l.at (i), 0)); + } + return ret; +} + +QList +PlaylistModel::getPosById (uint32_t id) +{ + QList ret; + int32_t pos = m_plist.indexOf (id); + + while (pos != -1) { + ret.append (pos); + pos = m_plist.indexOf (id, pos + 1); + } + + return ret; +} + +void +PlaylistModel::entry_changed (uint32_t id) +{ + QList pos = getPosById (id); + for (int i = 0; i < pos.size (); i ++) { + QModelIndex idx1 = index (pos.at (i), 0); + QModelIndex idx2 = index (pos.at (i), m_columns.size ()); + emit dataChanged(idx1, idx2); + } +} + +int +PlaylistModel::columnCount (const QModelIndex &parent) const +{ + return m_columns.size (); +} + +int +PlaylistModel::rowCount (const QModelIndex &parent) const +{ + if (!parent.isValid ()) { + return m_plist.size (); + } + + return 0; +} + +QModelIndex +PlaylistModel::parent (const QModelIndex &idx) const +{ + return QModelIndex (); +} + +QModelIndex +PlaylistModel::index (int row, int column, const QModelIndex &parent) const +{ + if (!parent.isValid ()) { + if (row > (m_plist.size () - 1)) + return QModelIndex (); + if (row < 0) + return QModelIndex (); + return createIndex (row, column, -1); + } + + return QModelIndex (); +} + +QVariant +PlaylistModel::data (const QModelIndex &index, int role) const +{ + if (!index.isValid ()) { + return QVariant (); + } + + if (index.row () >= m_plist.size ()) { + return QVariant (); + } + + if (role == MedialibIdRole) { + return QVariant (m_plist[index.row ()]); + } + + if (role == Qt::SizeHintRole) { + if (m_cached_size[index.column ()].isValid ()) { + return QVariant (m_cached_size[index.column ()]); + } + return QVariant (); + } + + if (role == Qt::DisplayRole || role == Qt::ToolTipRole) { + QString key = m_columns[index.column ()].toLower (); + QString fallkey = m_colfallback[index.column ()].toLower (); + + if (key == "#") { + return QVariant (index.row ()); + } else { + unsigned int id = m_plist[index.row ()]; + PlaylistModel *fake = const_cast (this); + QHash d = fake->m_client->cache ()->get_info (id); + + if (d.contains (key)) { + return QVariant (d[key]); + } else if (d.contains (fallkey)) { + return QVariant (d[fallkey]); + } + + return QVariant (); + } + } else if (role == CurrentEntryRole) { + int i = m_current_pos; + + if (index.row () == i) + return QVariant (true); + return QVariant (false); + } + + return QVariant (); +} + +QStringList +PlaylistModel::mimeTypes () const +{ + QStringList l ("application/x-xmms2poslist"); + l << "application/x-xmms2mlibid"; + l << "text/uri-list"; + return l; +} + +QMimeData * +PlaylistModel::mimeData (const QModelIndexList &list) const +{ + QMimeData *ret = new QMimeData (); + QByteArray ba; + QDataStream stream (&ba, QIODevice::WriteOnly); + + QList l; + for (int i = 0; i < list.size (); i ++) { + QModelIndex idx = list.at (i); + if (idx.column () != 0) + continue; + l.append (idx.row ()); + } + + stream << l; + ret->setData ("application/x-xmms2poslist", ba); + + return ret; +} + +bool +PlaylistModel::dropMimeData (const QMimeData *data, + Qt::DropAction action, + int row, int column, + const QModelIndex & parent) +{ + if (parent.internalId () != -1 && parent.isValid ()) { + return false; + } + + if (data->hasFormat ("application/x-xmms2poslist")) { + if (!parent.isValid ()) + return false; + + QByteArray ba = data->data ("application/x-xmms2poslist"); + QDataStream stream (&ba, QIODevice::ReadOnly); + QList l; + stream >> l; + qSort (l); + int target = parent.row (); + + int mod = 0; + + while (l.size ()) { + int orow = l.takeAt (0) - mod; + m_client->playlist ()->moveEntry (orow, target) (); + if (orow < target) { + mod ++; + } else { + target ++; + } + } + return true; + } else if (data->hasFormat ("application/x-xmms2mlibid")) { + QByteArray ba = data->data ("application/x-xmms2mlibid"); + QDataStream stream (&ba, QIODevice::ReadOnly); + QList l; + stream >> l; + + int target; + + if (parent.isValid ()) + target = parent.row () + 1; + else + target = m_plist.size () + 1; + + while (l.size ()) { + int id = l.takeAt (0); + if (target >= m_plist.size ()) { + m_client->playlist ()->addId (id) (); + } else { + m_client->playlist ()->insertId (target ++, id) (); + } + } + return true; + } else if (data->hasFormat ("text/uri-list")) { + int target; + + if (parent.isValid ()) + target = parent.row () + 1; + else + target = m_plist.size () + 1; + + QList l = data->urls (); + + qSort (l); + + for (int i = 0; i < l.size (); i++) { + QFileInfo fi (l.at (i).toLocalFile ()); + std::string s ("file:///"); + s.append (fi.absoluteFilePath ().toLocal8Bit ()); + if (fi.isFile ()) { + if (target >= m_plist.size ()) { + m_client->playlist ()->addUrl (s) (); + } else { + m_client->playlist ()->insertUrl (target ++, s) (); + } + } else if (fi.isDir ()) { + m_client->playlist ()->addRecursive (s) (); + } + } + + return true; + } + return false; +} + +Qt::DropActions +PlaylistModel::supportedDropActions () const +{ + return Qt::CopyAction | Qt::MoveAction; +} + +QVariant +PlaylistModel::headerData (int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) { + return QVariant (); + } + + if (orientation == Qt::Horizontal) { + if (section <= m_columns.size ()) + return QVariant (m_columns[section]); + } + + return QVariant (); +} + +Qt::ItemFlags +PlaylistModel::flags (const QModelIndex &idx) const +{ + unsigned int id = m_plist[idx.row ()]; + PlaylistModel *fake = const_cast (this); + QHash d = fake->m_client->cache ()->get_info (id); + + Qt::ItemFlags f = Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; + + if (idx.isValid ()) { + f |= Qt::ItemIsDropEnabled; + } + if (d.contains ("status") && d["status"] != XMMS_MEDIALIB_ENTRY_STATUS_NOT_AVAILABLE) { + f |= Qt::ItemIsEnabled; + } + + return f; +} + +QList +PlaylistModel::get_all_id () +{ + return m_plist; +} diff --git a/lib/playlistmodel.h b/lib/playlistmodel.h new file mode 100644 index 0000000..d4f6860 --- /dev/null +++ b/lib/playlistmodel.h @@ -0,0 +1,147 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#ifndef __PLAYLIST_MODEL_H__ +#define __PLAYLIST_MODEL_H__ + +#include + +#include +#include +#include +#include + +#include "xclient.h" + +/** + * @class PlaylistModel playlistmodel.h + * @brief A model that represents a playlist on the server + * + * This model will show the playlist and update it according to the + * changes from the server. This can be subclassed to be customized. +**/ +class PlaylistModel : public QAbstractItemModel +{ + Q_OBJECT + public: + /** + * The constructor for the PlaylistModel. + * @param parent The parent QObject for this model + * @param client The XClient object to be used in order to get the updates + * @param n The name of the playlist that this model should show + **/ + PlaylistModel (QObject *parent, XClient *client, const QString &n = "_active"); + + enum { + DisplayRole = Qt::DisplayRole, + ToolTipRole = Qt::ToolTipRole, + CurrentEntryRole = 200, + MedialibIdRole, + AvailableRole + }; + + int rowCount (const QModelIndex &parent) const; + int columnCount (const QModelIndex &parent) const; + QVariant data (const QModelIndex &index, int role = DisplayRole) const; + QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + Qt::ItemFlags flags (const QModelIndex &) const; + QModelIndex parent (const QModelIndex &) const; + QModelIndex index (int row, int column, const QModelIndex &idx = QModelIndex ()) const; + QMimeData *mimeData (const QModelIndexList &list) const; + bool dropMimeData (const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent); + Qt::DropActions supportedDropActions () const; + QStringList mimeTypes () const; + + /** + * Set the columns that should be shown in the view. + * @param columns A list of property keys. i.e. "artist", "album" + **/ + void setColumns (const QList &columns); + + /** + * Set fallback columns. A fallback column is what should be shown + * if the first column is not available for that entry. + * @param columns A list of property keys. + **/ + void setColumnFallback (const QList &columns); + + /** + * Return the current columns. + **/ + QList columns () const; + + /** + * Return a list of all entry ids that are currently in the list. + **/ + QList get_all_id (); + + void set_cached_size (int i, const QSize &size) { + m_cached_size[i] = size; + }; + + QSize cached_size (int i) const { + return m_cached_size[i]; + }; + + /** + * Return a list of QModelIndex for the entry. Since one + * entry can be in the Playlist multiple times we need to + * return a list of indexes. + * @ + **/ + QModelIndexList get_idxlist_by_id (uint32_t); + + QModelIndex current_playlist_pos () const { + return index (m_current_pos, 0); + }; + + void set_playlist (const QString &); + + protected: + XClient *m_client; + QList < unsigned int > m_plist; + QList < uint32_t > getPosById (uint32_t id); + QList < QString > m_columns; + QList < QString > m_colfallback; + + signals: + void entryMoved (const QModelIndex &, const QModelIndex &); + + public slots: + void got_connection (XClient *); + void entry_changed (uint32_t); + + private: + bool handle_list (const Xmms::List< unsigned int > &list); + bool handle_change (const Xmms::Dict &chg); + bool handle_update_pos (const unsigned int &pos); + bool handle_pls_loaded (const std::string &); + bool handle_current_pls (const std::string &); + + void getInfo (unsigned int id) const; + + + uint32_t m_current_pos; + bool m_isactive; + + QList m_cached_size; + + QString m_name; + +}; + +#endif diff --git a/lib/xclient.cpp b/lib/xclient.cpp new file mode 100644 index 0000000..c7d7fb5 --- /dev/null +++ b/lib/xclient.cpp @@ -0,0 +1,210 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#include + +#include +#include +#include +#include +#include + +#include "xclient.h" +#include "xmmsqt4.h" +#include "debug.h" + +XSettings::XSettings (QObject *parent) : QObject (parent) +{ + /* dummy */ +} + +void +XSettings::change_settings () +{ + emit settingsChanged (); +} + +QString +XClient::stdToQ (const std::string &str) +{ + return QString::fromUtf8 (str.c_str ()); +} + +std::string +XClient::qToStd (const QString &str) +{ + return std::string (str.toUtf8 ().data ()); +} + +QDir +XClient::esperanza_dir () +{ + QDir c (stdToQ (Xmms::getUserConfDir ())); + if (!c.cd ("clients/Esperanza")) { + c.mkpath ("clients/Esperanza"); + if (!c.cd ("clients/Esperanza")) { + qDebug ("couldn't open dir"); + } + return c; + } else { + return c; + } + return QDir (); +} + +XClient::XClient (QObject *parent, const std::string &name) : QObject (parent), m_sync (name + "-sync") +{ + m_client = NULL; + m_isconnected = false; + m_cache = new XClientCache (this, this); + m_settings = new XSettings (this); + m_name = name; +} + +void XClient::disconnect () +{ + delete m_client; + m_client = NULL; + m_isconnected = false; +} + +bool +XClient::connect (const char *ipcpath, const bool &sync, QWidget *parent) +{ + bool tried_once = false; +try_again: + + try { + delete m_client; + m_client = new Xmms::Client (m_name); + if (!ipcpath || ipcpath == "") + m_client->connect (NULL); + else + m_client->connect (ipcpath); + } + catch (Xmms::connection_error& e) { + if (ipcpath == NULL && !tried_once) { + QSettings s; + if (s.value ("core/autostart", true).toBool ()) { + if (!system ("xmms2-launcher")) { + tried_once = true; + goto try_again; + } + } + } + + QErrorMessage *err = new QErrorMessage (parent); + err->showMessage ("Couldn't connect to XMMS2, please try again."); + err->exec (); + delete err; + return false; + } + + m_client->setMainloop (new XmmsQT4 (m_client->getConnection ())); + + if (sync) { + try { + m_sync.connect (ipcpath); + } + catch (Xmms::connection_error &e) { + qWarning ("Couldn't establish sync connection!"); + } + } + + m_isconnected = true; + emit gotConnection (this); + + return true; +} + +void +XClient::dictToQHash (const std::string &key, + const Xmms::Dict::Variant &value, + QHash &hash) +{ + if (value.type () == typeid (int32_t)) { + hash.insert (QString::fromLatin1 (key.c_str ()), + QVariant (boost::get< int32_t > (value))); + } else if (value.type () == typeid (uint32_t)) { + hash.insert (QString::fromLatin1 (key.c_str ()), + QVariant (boost::get< uint32_t > (value))); + } else { + QString val; + val = QString::fromUtf8 (boost::get< std::string > (value).c_str ()); + hash.insert (stdToQ (key), QVariant (val)); + } +} + +/** + * convert a Xmms::Dict to a QHash +**/ +QHash +XClient::convert_dict (const Xmms::Dict &dict) +{ + QHash hash; + dict.each (boost::bind (&XClient::dictToQHash, + _1, _2, boost::ref (hash))); + + return hash; +} + + +void +XClient::propDictToQHash (const std::string &key, + const Xmms::Dict::Variant &value, + const std::string &source, + QHash &hash) +{ + if (value.type () == typeid (int32_t)) { + hash.insert (QString::fromLatin1 (key.c_str ()), + QVariant (boost::get< int32_t > (value))); + } else if (value.type () == typeid (uint32_t)) { + hash.insert (QString::fromLatin1 (key.c_str ()), + QVariant (boost::get< uint32_t > (value))); + } else { + QString val; + if (key == "url") { + /* This really is wrong ...*/ + char *c = const_cast(xmmsc_result_decode_url (NULL, boost::get< std::string >(value).c_str ())); + val = QString::fromUtf8 (c); + val = val.mid (val.lastIndexOf ("/") + 1); + if (val.isEmpty ()) { + val = QString::fromUtf8 (c); + } + free (c); + } else { + val = QString::fromUtf8 (boost::get< std::string > (value).c_str ()); + } + + hash.insert (stdToQ (key), QVariant (val)); + } +} + +/** + * convert a Xmms::PropDict to a QHash +**/ +QHash +XClient::convert_propdict (const Xmms::PropDict &dict) +{ + QHash hash; + dict.each (boost::bind (&XClient::propDictToQHash, + _1, _2, _3, boost::ref (hash))); + + return hash; +} + + diff --git a/lib/xclient.h b/lib/xclient.h new file mode 100644 index 0000000..5036e15 --- /dev/null +++ b/lib/xclient.h @@ -0,0 +1,110 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#ifndef __XCLIENT_H__ +#define __XCLIENT_H__ + +#include + +class XClient; + +#include +#include +#include +#include +#include + +#include "xclientcache.h" + +class XSettings : public QObject +{ + Q_OBJECT + public: + XSettings (QObject *); + void change_settings (); + + signals: + void settingsChanged (); +}; + +class XClient : public QObject { + Q_OBJECT + public: + XClient (QObject *, const std::string &); + + void disconnect (); + bool connect (const char *path = NULL, const bool &sync = false, QWidget* parent = NULL); + static void propDictToQHash (const std::string &key, + const Xmms::Dict::Variant &value, + const std::string &source, + QHash &hash); + + static void dictToQHash (const std::string &key, + const Xmms::Dict::Variant &value, + QHash &hash); + + static QHash convert_propdict (const Xmms::PropDict &); + static QHash convert_dict (const Xmms::Dict &); + + XClientCache *cache () const { + return m_cache; + }; + + XSettings *settings () const { + return m_settings; + }; + + const Xmms::Client *sync () const { + return &m_sync; + }; + + static QString stdToQ (const std::string &); + static std::string qToStd (const QString &); + + bool isConnected () const { + return m_isconnected; + }; + + static QDir esperanza_dir (); + void setDisconnectCallback (const Xmms::DisconnectCallback::slot_type &slot) { m_client->setDisconnectCallback (slot); } + const Xmms::Collection* collection () { if (m_client && m_client->isConnected ()) return &m_client->collection; else return NULL; } + const Xmms::Playlist* playlist () { if (m_client && m_client->isConnected ()) return &m_client->playlist; else return NULL; } + const Xmms::Playback* playback () { if (m_client && m_client->isConnected ()) return &m_client->playback; else return NULL; } + const Xmms::Medialib* medialib () { if (m_client && m_client->isConnected ()) return &m_client->medialib; else return NULL; } + const Xmms::Bindata* bindata () { if (m_client && m_client->isConnected ()) return &m_client->bindata; else return NULL; } + const Xmms::Config* config () { if (m_client && m_client->isConnected ()) return &m_client->config; else return NULL; } + const Xmms::Stats* stats () { if (m_client && m_client->isConnected ()) return &m_client->stats; else return NULL; } + + signals: + void gotConnection (XClient *); + + + protected: + Xmms::Client *m_client; + + private: + std::string m_name; +// Xmms::Client *m_client; + XClientCache *m_cache; + XSettings *m_settings; + bool m_isconnected; + + Xmms::Client m_sync; +}; + + +#endif diff --git a/lib/xclientcache.cpp b/lib/xclientcache.cpp new file mode 100644 index 0000000..653074b --- /dev/null +++ b/lib/xclientcache.cpp @@ -0,0 +1,167 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#include "xclientcache.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +XClientCache::XClientCache (QObject *parent, XClient *client) : QObject (parent) +{ + QSettings s; + connect (client, SIGNAL (gotConnection (XClient *)), this, SLOT (got_connection (XClient *))); + QPixmapCache::setCacheLimit (s.value ("core/pixmapcache").toInt ()); +} + +void +XClientCache::got_connection (XClient *client) +{ + m_client = client; + client->playback ()->signalPlaytime () (Xmms::bind (&XClientCache::handle_playtime, this)); + client->playback ()->getPlaytime () (Xmms::bind (&XClientCache::handle_playtime, this)); + + client->medialib ()->broadcastEntryChanged () (Xmms::bind (&XClientCache::handle_mlib_entry_changed, this)); +} + +bool +XClientCache::handle_medialib_info_error (const std::string &error, uint32_t id) +{ + /* we probably couldn't find that entry, let's remove it */ + m_info.remove (id); + emit entryRemoved (id); + return true; +} + +bool +XClientCache::handle_medialib_info (const Xmms::PropDict &info) +{ + int32_t id = info.get ("id"); + QHash hash = XClient::convert_propdict (info); + + m_info.insert (id, hash); + emit entryChanged (id); + + return true; +} + +void +XClientCache::extra_info_set (uint32_t id, const QString &name, + const QVariant &value) +{ + m_extra_info[id][name] = value; +} + +QVariant +XClientCache::extra_info_get (uint32_t id, const QString &name) +{ + return m_extra_info[id][name]; +} + +void +XClientCache::invalidate (uint32_t id) +{ + m_info.remove (id); +} + +void +XClientCache::invalidate_all () +{ + m_info.clear (); +} + +bool +XClientCache::handle_bindata (const Xmms::bin &data, const QString &id) +{ + QPixmap i; + i.loadFromData (data.c_str (), data.size()); + + if (i.isNull ()) { + return true; + } + + /* conserve memory client side */ + if (i.width () < 300) { + i = i.scaledToWidth (300, Qt::SmoothTransformation); + } + + QPixmapCache::insert (id, i); + + QList ids = m_icon_map[id]; + for (int i = 0; i < ids.size (); i++) { + emit entryChanged (ids.at (i)); + } + + return true; +} + +QIcon +XClientCache::get_icon (uint32_t id) +{ + return QIcon (get_pixmap (id)); +} + +QPixmap +XClientCache::get_pixmap (uint32_t id) +{ + if (m_info[id].contains ("picture_front")) { + QString hash = m_info[id]["picture_front"].toString (); + QPixmap p; + + if (!QPixmapCache::find (hash, p)) { + m_client->bindata ()->retrieve (hash.toStdString ()) ( + boost::bind (&XClientCache::handle_bindata, this, _1, hash)); + QPixmapCache::insert (hash, QPixmap ()); + m_icon_map[hash].append (id); + } + + return p; + } + return QPixmap (); +} + +QHash +XClientCache::get_info (uint32_t id) +{ + if (!m_info.contains (id)) { + m_client->medialib ()->getInfo (id) (Xmms::bind (&XClientCache::handle_medialib_info, this), + boost::bind (&XClientCache::handle_medialib_info_error, this, _1, id)); + m_info[id] = QHash (); + } + + return m_info[id]; +} + +bool +XClientCache::handle_mlib_entry_changed (const uint32_t &id) +{ + m_client->medialib ()->getInfo (id) (Xmms::bind (&XClientCache::handle_medialib_info, this)); + return true; +} + + +bool +XClientCache::handle_playtime (const unsigned int &tme) +{ + emit playtime(tme); + return true; +} diff --git a/lib/xclientcache.h b/lib/xclientcache.h new file mode 100644 index 0000000..9df7fa9 --- /dev/null +++ b/lib/xclientcache.h @@ -0,0 +1,80 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#ifndef __XCLIENTCACHE_H__ +#define __XCLIENTCACHE_H__ + +class XClientCache; + +#include "xclient.h" + +#include +#include +#include +#include +#include +#include +#include + +class XClientCache : public QObject +{ + Q_OBJECT + public: + XClientCache (QObject *, XClient *); + + QHash get_info (uint32_t id); + QIcon get_icon (uint32_t id); + QPixmap get_pixmap (uint32_t id); + QVariant extra_info_get (uint32_t, const QString &); + + void extra_info_set (uint32_t, const QString &, const QVariant &); + void invalidate (uint32_t); + void invalidate_all (); + + bool extra_info_has (uint32_t id, const QString &s) { + if (m_extra_info.contains (id)) + if (m_extra_info[id].contains (s)) + return true; + return false; + }; + + signals: + void entryChanged (uint32_t); + void entryRemoved (uint32_t); + void playtime (uint32_t); + + public slots: + void got_connection (XClient *); + + private: + bool handle_medialib_info (const Xmms::PropDict &info); + bool handle_medialib_info_error (const std::string &, uint32_t); + + bool handle_mlib_entry_changed (const uint32_t &id); + bool handle_bindata (const Xmms::bin &, const QString &); + + bool handle_playtime (const unsigned int &tme); + + QHash< uint32_t, QHash > m_info; + + QHash < QString, QList > m_icon_map; + QHash < int, QHash < QString, QVariant > > m_extra_info; + + XClient *m_client; +}; + +#endif diff --git a/XmmsQT4.cpp b/lib/xmmsqt4.cpp similarity index 69% rename from XmmsQT4.cpp rename to lib/xmmsqt4.cpp index 42b3b02..ef5d680 100644 --- a/XmmsQT4.cpp +++ b/lib/xmmsqt4.cpp @@ -1,6 +1,23 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + #include #include -#include "XmmsQT4.h" +#include "xmmsqt4.h" #include #include diff --git a/lib/xmmsqt4.h b/lib/xmmsqt4.h new file mode 100644 index 0000000..a3391ab --- /dev/null +++ b/lib/xmmsqt4.h @@ -0,0 +1,50 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + +#ifndef __XMMSQT4_H__ +#define __XMMSQT4_H__ + +#include + +#include +#include +#include + +class XmmsQT4 : public QObject, public Xmms::MainloopInterface +{ + Q_OBJECT + public: + XmmsQT4(xmmsc_connection_t *xmmsc); + ~XmmsQT4(); + + void run (); + + void ToggleWrite(bool toggle); + xmmsc_connection_t *GetXmmsConnection(); + + public slots: + void OnRead (); + void OnWrite (); + + private: + int m_fd; + QSocketNotifier *m_rsock; + QSocketNotifier *m_wsock; + xmmsc_connection_t *m_xmmsc; +}; + +#endif diff --git a/promoe.pro b/promoe.pro index 57f20cf..c727e33 100644 --- a/promoe.pro +++ b/promoe.pro @@ -1,82 +1,4 @@ -SOURCES += XmmsQT4.cpp \ - PixWidget.cpp \ - Skin.cpp \ - MainWindow.cpp \ - Display.cpp \ - MainDisplay.cpp \ - TitleBar.cpp \ - Button.cpp \ - TextBar.cpp \ - NumberDisplay.cpp \ - TimeDisplay.cpp \ - XMMSHandler.cpp \ - SmallNumberDisplay.cpp \ - StereoMono.cpp \ - PosBar.cpp \ - PlayStatus.cpp \ - ShadedDisplay.cpp \ - Playlist.cpp \ - PlaylistList.cpp \ - SkinChooser.cpp \ - PlaylistShade.cpp \ - qtmd5.cpp \ - SettingsWindow.cpp \ - PlaylistMenu.cpp \ - VolumeSlider.cpp \ - ClutterBar.cpp \ - Equalizer.cpp \ - FileDialog.cpp \ - BrowseModel.cpp \ - BrowseDialog.cpp - - -HEADERS += XmmsQT4.h \ - PixWidget.h \ - Skin.h \ - MainWindow.h \ - Display.h \ - MainDisplay.h \ - TitleBar.h \ - Button.h \ - TextBar.h \ - NumberDisplay.h \ - TimeDisplay.h \ - XMMSHandler.h \ - SmallNumberDisplay.h \ - StereoMono.h \ - PosBar.h \ - PlayStatus.h \ - ShadedDisplay.h \ - Playlist.h \ - PlaylistList.h \ - SkinChooser.h \ - PlaylistShade.h \ - qtmd5.h \ - SettingsWindow.h \ - PlaylistMenu.h \ - VolumeSlider.h \ - ClutterBar.h \ - Equalizer.h \ - FileDialog.h \ - BrowseModel.h \ - BrowseDialog.h - - - -RESOURCES = promoe.qrc -macx:RC_FILE = promoe.icns -macx:INCLUDEPATH = /sw/include - -QT += network -;macx:QTPLUGIN += qjpeg -QMAKE_LFLAGS += -L$$[QT_INSTALL_PLUGINS]/imageformats - -CONFIG += link_pkgconfig - -QMAKE_CXXFLAGS += -g -;CONFIG += debug warn_on -QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter -PKGCONFIG += xmms2-client xmms2-client-cpp - -;CONFIG += avahi +TEMPLATE = subdirs +CONFIG += ordered +SUBDIRS = lib src diff --git a/BrowseDialog.cpp b/src/BrowseDialog.cpp similarity index 100% rename from BrowseDialog.cpp rename to src/BrowseDialog.cpp diff --git a/BrowseDialog.h b/src/BrowseDialog.h similarity index 100% rename from BrowseDialog.h rename to src/BrowseDialog.h diff --git a/BrowseModel.cpp b/src/BrowseModel.cpp similarity index 96% rename from BrowseModel.cpp rename to src/BrowseModel.cpp index 7fdaff8..1e996ca 100644 --- a/BrowseModel.cpp +++ b/src/BrowseModel.cpp @@ -36,8 +36,7 @@ void BrowseModel::setPath (const QModelIndex &index) { BrowseModelItem *item = m_list.at (index.row ()); - m_client->xform.browse (item->data("path").toStdString (), - Xmms::bind (&BrowseModel::list_cb, this)); + m_client->xform.browse (item->data("path").toStdString ()) (Xmms::bind (&BrowseModel::list_cb, this)); m_current_dir = item->data ("path"); } @@ -47,7 +46,7 @@ BrowseModel::setPath (const QString &path) if (path.isEmpty()) list_root (); - m_client->xform.browse (path.toStdString (), + m_client->xform.browse (path.toStdString ())( Xmms::bind (&BrowseModel::list_cb, this), Xmms::bind (&BrowseModel::list_err, this)); m_current_dir = path; diff --git a/BrowseModel.h b/src/BrowseModel.h similarity index 100% rename from BrowseModel.h rename to src/BrowseModel.h diff --git a/Button.cpp b/src/Button.cpp similarity index 100% rename from Button.cpp rename to src/Button.cpp diff --git a/Button.h b/src/Button.h similarity index 100% rename from Button.h rename to src/Button.h diff --git a/ClutterBar.cpp b/src/ClutterBar.cpp similarity index 100% rename from ClutterBar.cpp rename to src/ClutterBar.cpp diff --git a/ClutterBar.h b/src/ClutterBar.h similarity index 100% rename from ClutterBar.h rename to src/ClutterBar.h diff --git a/Display.cpp b/src/Display.cpp similarity index 100% rename from Display.cpp rename to src/Display.cpp diff --git a/Display.h b/src/Display.h similarity index 100% rename from Display.h rename to src/Display.h diff --git a/Equalizer.cpp b/src/Equalizer.cpp similarity index 100% rename from Equalizer.cpp rename to src/Equalizer.cpp diff --git a/Equalizer.h b/src/Equalizer.h similarity index 100% rename from Equalizer.h rename to src/Equalizer.h diff --git a/FileDialog.cpp b/src/FileDialog.cpp similarity index 100% rename from FileDialog.cpp rename to src/FileDialog.cpp diff --git a/FileDialog.h b/src/FileDialog.h similarity index 100% rename from FileDialog.h rename to src/FileDialog.h diff --git a/MainDisplay.cpp b/src/MainDisplay.cpp similarity index 95% rename from MainDisplay.cpp rename to src/MainDisplay.cpp index 461f946..41da137 100644 --- a/MainDisplay.cpp +++ b/src/MainDisplay.cpp @@ -72,8 +72,10 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) this, SLOT(setMediainfo (const Xmms::PropDict &))); connect (&xmmsh, SIGNAL(playbackStatusChanged(Xmms::Playback::Status)), this, SLOT(setStatus(Xmms::Playback::Status))); - connect (&xmmsh, SIGNAL(playtimeChanged(uint)), - this, SLOT(setPlaytime(uint))); +// connect (&xmmsh, SIGNAL(playtimeChanged(uint)), +// this, SLOT(setPlaytime(uint))); + connect (xmmsh.cache () , SIGNAL (playtime (uint32_t)), + this, SLOT (setPlaytime (uint32_t))); connect (&xmmsh, SIGNAL(getVolume(uint)), this, SLOT(updateVolume(uint))); connect (m_vslider, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int))); xmmsh.volumeGet(); @@ -113,8 +115,7 @@ void MainDisplay::setPixmaps (Skin *skin) { QPalette palette = QPalette(); - QBrush brush = QBrush(Qt::TexturePattern); - brush.setTexture(skin->getItem(Skin::MAIN_WINDOW)); + QBrush brush = QBrush(skin->getItem(Skin::MAIN_WINDOW)); palette.setBrush(QPalette::Background, brush); setPalette(palette); @@ -133,9 +134,9 @@ MainDisplay::setStatus (Xmms::Playback::Status status) } void -MainDisplay::setPlaytime (uint time) +MainDisplay::setPlaytime (uint32_t time) { - uint showtime; + uint32_t showtime; if (m_mw->isTimemodeReverse()) { uint maxtime = m_posbar->getMax(); showtime = -(maxtime - time); diff --git a/MainDisplay.h b/src/MainDisplay.h similarity index 98% rename from MainDisplay.h rename to src/MainDisplay.h index b28e8f6..a6a5a75 100644 --- a/MainDisplay.h +++ b/src/MainDisplay.h @@ -70,7 +70,7 @@ class MainDisplay : public SkinDisplay public slots: void setPixmaps(Skin *skin); void setStatus (Xmms::Playback::Status status); - void setPlaytime (uint time); + void setPlaytime (uint32_t time); void setMediainfo (const Xmms::PropDict &); void togglePL(void); void toggleEQ(void); diff --git a/MainWindow.cpp b/src/MainWindow.cpp similarity index 100% rename from MainWindow.cpp rename to src/MainWindow.cpp diff --git a/MainWindow.h b/src/MainWindow.h similarity index 98% rename from MainWindow.h rename to src/MainWindow.h index 74fd150..ed35632 100644 --- a/MainWindow.h +++ b/src/MainWindow.h @@ -14,7 +14,7 @@ class MainWindow; #include #include -#include "XmmsQT4.h" +#include "xmmsqt4.h" /* #include "Skin.h" diff --git a/MedialibItem.h b/src/MedialibItem.h similarity index 100% rename from MedialibItem.h rename to src/MedialibItem.h diff --git a/MedialibTreeModel.cpp b/src/MedialibTreeModel.cpp similarity index 100% rename from MedialibTreeModel.cpp rename to src/MedialibTreeModel.cpp diff --git a/MedialibTreeModel.h b/src/MedialibTreeModel.h similarity index 100% rename from MedialibTreeModel.h rename to src/MedialibTreeModel.h diff --git a/MedialibView.cpp b/src/MedialibView.cpp similarity index 100% rename from MedialibView.cpp rename to src/MedialibView.cpp diff --git a/MedialibView.h b/src/MedialibView.h similarity index 89% rename from MedialibView.h rename to src/MedialibView.h index 5aa1b84..31bdffd 100644 --- a/MedialibView.h +++ b/src/MedialibView.h @@ -1,7 +1,6 @@ #ifndef __MEDIALIBVIEW_H__ #define __MEDIALIBVIEW_H__ -#include "XMMSSocket.h" #include #include diff --git a/MedialibWindow.cpp b/src/MedialibWindow.cpp similarity index 100% rename from MedialibWindow.cpp rename to src/MedialibWindow.cpp diff --git a/MedialibWindow.h b/src/MedialibWindow.h similarity index 100% rename from MedialibWindow.h rename to src/MedialibWindow.h diff --git a/NumberDisplay.cpp b/src/NumberDisplay.cpp similarity index 93% rename from NumberDisplay.cpp rename to src/NumberDisplay.cpp index 7688ca5..8ea9aaf 100644 --- a/NumberDisplay.cpp +++ b/src/NumberDisplay.cpp @@ -21,8 +21,7 @@ NumberDisplay::NumberDisplay (QWidget *parent, TimeDisplay *td,uint w, uint star void NumberDisplay::setPixmaps (Skin *skin) { - QBrush b (Qt::TexturePattern); - b.setTexture (skin->getNumber (10)); + QBrush b (skin->getNumber (10)); QPainter paint; paint.begin (&m_pixmap); diff --git a/NumberDisplay.h b/src/NumberDisplay.h similarity index 100% rename from NumberDisplay.h rename to src/NumberDisplay.h diff --git a/PixWidget.cpp b/src/PixWidget.cpp similarity index 100% rename from PixWidget.cpp rename to src/PixWidget.cpp diff --git a/PixWidget.h b/src/PixWidget.h similarity index 100% rename from PixWidget.h rename to src/PixWidget.h diff --git a/PlayStatus.cpp b/src/PlayStatus.cpp similarity index 100% rename from PlayStatus.cpp rename to src/PlayStatus.cpp diff --git a/PlayStatus.h b/src/PlayStatus.h similarity index 100% rename from PlayStatus.h rename to src/PlayStatus.h diff --git a/Playlist.cpp b/src/Playlist.cpp similarity index 76% rename from Playlist.cpp rename to src/Playlist.cpp index 9c95af3..b100970 100644 --- a/Playlist.cpp +++ b/src/Playlist.cpp @@ -1,7 +1,8 @@ #include "MainWindow.h" #include "BrowseDialog.h" #include "Playlist.h" -#include "PlaylistList.h" +#include "PlaylistView.h" +#include "playlistmodel.h" #include "PlaylistShade.h" #include "PlaylistMenu.h" @@ -15,30 +16,139 @@ #include #include -PlaylistScrollButton::PlaylistScrollButton (PlaylistScroller *parent, uint normal, uint pressed) : Button (parent, normal, pressed, true) +/* + * + * PlaylistScrollBar + * + */ +PlaylistScrollBar::PlaylistScrollBar (QWidget *parent) : + QScrollBar (Qt::Vertical, parent) { - m_slider = parent; + Skin *skin = Skin::getInstance (); + + setContextMenuPolicy(Qt::NoContextMenu); + + m_pixmap = QPixmap (0, 0); + m_slider = QPixmap (0, 0); + m_slider_down = QPixmap (0, 0); + + connect (skin, SIGNAL (skinChanged (Skin *)), + this, SLOT (setPixmaps(Skin *))); } void -PlaylistScrollButton::mouseMoveEvent (QMouseEvent *event) +PlaylistScrollBar::mouseMoveEvent (QMouseEvent *event) { - QPoint p (event->pos ()); + if (!isSliderDown ()) + return; - int npos = pos().y()+p.y()-m_diffy; - if (npos >= 0 && npos + rect().height() <= m_slider->rect().height()) { - move (0, npos); - } else if (npos < 0) { - move (0, 0); - npos = 0; - } else if (npos + rect().height() > m_slider->rect().height()) { - move (0, m_slider->rect().height()-rect().height()); - npos = m_slider->rect().height()-rect().height(); - } + int tmp = sliderValueFromPosition(event->y () - m_sliderOffset); + if (tmp == value()) + return; - m_slider->doScroll (); + setValue(tmp); + + //TODO only repaint necessyry range + repaint (); } +void +PlaylistScrollBar::mousePressEvent (QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) { + event->ignore(); + return; + } + + if (maximum () == minimum ()) + return; + + int sliderBase = sliderPositionFromValue(); + if (event->y () < sliderBase) { + triggerAction (QAbstractSlider::SliderPageStepSub); + } else if (event->y () > sliderBase + m_slider.height ()) { + triggerAction (QAbstractSlider::SliderPageStepAdd); + } else { + m_sliderOffset = event->y () - sliderBase; + setSliderDown (true); + } + + //TODO only repaint necessary range + repaint (); +} + +void +PlaylistScrollBar::mouseReleaseEvent (QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) { + event->ignore(); + return; + } + + if (isSliderDown ()) { + setValue(sliderValueFromPosition(event->y () - m_sliderOffset)); + setSliderDown (false); + } + + //TODO only repaint necessary range + repaint (); +} + +void +PlaylistScrollBar::paintEvent (QPaintEvent *event) +{ + if (m_pixmap.isNull ()) { + return; + } + +// TODO remove, in here for debuging +// qDebug("%i %i %i %i %i %i %i", event->rect ().x(), event->rect ().y(), event->rect ().width(), event->rect ().height(), +// minimum(), maximum (), sliderPosition ()); + + QPainter (paint); + paint.begin (this); + /* draw background */ + paint.drawPixmap (event->rect (), m_pixmap, m_pixmap.rect ()); + /* draw slider */ + QPixmap *slider = isSliderDown () ? &m_slider_down : &m_slider ; + QRect rect (slider->rect ()); + rect.moveTop (sliderPositionFromValue ()); + paint.drawPixmap (rect , *slider, slider->rect ()); + paint.end (); +} + + +void +PlaylistScrollBar::setPixmaps (Skin *skin) +{ + m_pixmap = skin->getPls (Skin::PLS_RFILL2_0); + m_slider = skin->getPls (Skin::PLS_SCROLL_0); + m_slider_down = skin->getPls (Skin::PLS_SCROLL_1); +} + + +int +PlaylistScrollBar::sliderPositionFromValue () +{ + return QStyle::sliderPositionFromValue (minimum (), maximum (), + sliderPosition (), + height () - m_slider.height (), + false); +} + +int +PlaylistScrollBar::sliderValueFromPosition (int position) +{ + return QStyle::sliderValueFromPosition (minimum (), maximum (), + position, + height () - m_slider.height (), + false); +} + + +/* + * dragButton + */ void dragButton::mouseMoveEvent (QMouseEvent *event) { @@ -47,68 +157,10 @@ dragButton::mouseMoveEvent (QMouseEvent *event) pw->size().height()+(event->pos().y()-m_diffy)); } -PlaylistScroller::PlaylistScroller (PlaylistWidget *parent) : QWidget (parent) -{ - Skin *skin = Skin::getInstance (); - - m_pixmap = QPixmap(0,0); - - connect (skin, SIGNAL (skinChanged (Skin *)), - this, SLOT (setPixmaps(Skin *))); - - m_button = new PlaylistScrollButton (this, Skin::PLS_SCROLL_0, Skin::PLS_SCROLL_1); - m_button->move (0, 0); -} - -void -PlaylistScroller::setMax (uint max) -{ - m_max = max; - repositionButton (); -} - -uint -PlaylistScroller::getMax (void) -{ - return rect().height()-m_button->rect().height(); -} - -uint -PlaylistScroller::getPos (void) -{ - return (int)((float)(m_button->pos ().y ()) / (float)getMax() * (float)m_max); -} - -void -PlaylistScroller::setPixmaps (Skin *skin) -{ - m_pixmap = skin->getPls (Skin::PLS_RFILL2_0); -} - -void -PlaylistScroller::repositionButton (void) -{ - PlaylistWidget *pw = dynamic_cast(parent ()); - /* x = 182.6 / (454 - 242) * 224 */ - int bpos = (int)((float)(pw->getOffset ()) / (float)m_max * (float) getMax ()); - if (bpos > getMax ()) - bpos = getMax (); - m_button->move (0, bpos); -} - -void -PlaylistScroller::paintEvent (QPaintEvent *event) -{ - if (m_pixmap.isNull ()) { - return; - } - - QPainter (paint); - paint.begin (this); - paint.drawPixmap (event->rect (), m_pixmap, m_pixmap.rect ()); - paint.end (); -} +/* + * PlaylistWindow + */ PlaylistWindow::PlaylistWindow (QWidget *parent) : QMainWindow (parent) { QSettings s; @@ -236,6 +288,9 @@ PlaylistWindow::leaveEvent (QEvent *event) } +/* + * PlaylistWidget + */ PlaylistWidget::PlaylistWidget (QWidget *parent) : QWidget (parent) { Skin *skin = Skin::getInstance (); @@ -248,12 +303,26 @@ PlaylistWidget::PlaylistWidget (QWidget *parent) : QWidget (parent) m_view = new PlaylistView (this); m_view->move (10, 20); m_view->resize (size().width()-30, size().height()-20-38); + m_view->setModel (XMMSHandler::getInstance().getPlaylistModel()); - m_list = new PlaylistList (m_view); + //m_list = new PlaylistList (m_view); - m_scroller = new PlaylistScroller (this); - connect (m_scroller, SIGNAL(scrolled(int)), this, SLOT(doScroll (int))); - connect (m_list, SIGNAL(sizeChanged(QSize)), this, SLOT(sizeChangedList (QSize))); + /* + * This is a hack to make PlaylistScrollBar work with PlaylistView. + * It is necessery because of limitations and at least one Bug in the + * QT library (as of Version 4.3 + * TODO: This might in a future Qt version. Try to find a better solution + */ + //m_scroller = new PlaylistScrollBar (this); + m_scrollBar = new PlaylistScrollBar (this); + m_view->setVerticalScrollBar (m_scrollBar); + m_scrollBar->setParent(this); + m_scrollBar->show(); + /* Workarounds for another QT bug (at least in my opinion) */ + connect (m_scrollBar, SIGNAL(actionTriggered (int)), + m_view, SLOT(verticalScrollbarAction (int))); + connect (m_scrollBar, SIGNAL(valueChanged (int)), + m_view, SLOT(verticalScrollbarValueChanged (int))); m_drag = new dragButton (this); m_drag->resize (30, 30); @@ -294,7 +363,7 @@ PlaylistWidget::addButtons (void) Skin::PLS_DEL_CRP_1); b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_FIL_0, Skin::PLS_DEL_FIL_1); - connect (b, SIGNAL(activated ()), m_list, SLOT (deleteFiles ())); +// connect (b, SIGNAL(activated ()), m_list, SLOT (deleteFiles ())); m_sel = new PlaylistMenu (this, Skin::PLS_SEL, Skin::PLS_SEL_DEC); @@ -383,43 +452,22 @@ PlaylistWidget::menuAddFile () } -void -PlaylistWidget::sizeChangedList (QSize s) -{ - m_scroller->setMax (s.height() - m_view->height()); -} - -void -PlaylistWidget::doScroll (int pos) -{ - m_list->setOffset (pos); - if (pos == 0) { - m_list->update (); - } else { - m_list->scroll (0, pos); - } - QApplication::sendPostedEvents (m_list, 0); -} - void PlaylistWidget::resizeEvent (QResizeEvent *event) { m_view->resize (size().width()-30, size().height()-20-38); - m_list->setSize (m_view->size().width(), m_view->size().height()); /* since the sizes has changed we need to move the buttons */ - m_scroller->move (size().width()-m_rfill3.width()-m_rfill2.width(), + m_scrollBar->move (size().width()-m_rfill3.width()-m_rfill2.width(), m_corner2.height()); - m_scroller->resize (m_rfill2.width(), + m_scrollBar->resize (m_rfill2.width(), size().height()-m_corner2.height()-m_corner4.height()); - m_scroller->setMax (m_list->height() - m_view->height()); - /* drag corner */ m_drag->move (size().width()-30, size().height()-30); - /* move add menu */ + /* move menus */ m_add->move (11, height() - m_add->height() - 12); m_del->move (40, height() - m_del->height() - 12); m_sel->move (69, height() - m_sel->height() - 12); @@ -469,13 +517,6 @@ PlaylistWidget::setActive (bool active) update (); } - -uint -PlaylistWidget::getOffset (void) -{ - return m_list->getOffset (); -} - void PlaylistWidget::mouseDoubleClickEvent (QMouseEvent *event) { diff --git a/Playlist.h b/src/Playlist.h similarity index 72% rename from Playlist.h rename to src/Playlist.h index e23f82f..ddbb124 100644 --- a/Playlist.h +++ b/src/Playlist.h @@ -5,6 +5,7 @@ #include #include +#include class MainWindow; class PlaylistWidget; @@ -13,10 +14,38 @@ class PlaylistScroller; #include "Button.h" class Skin; -class PlaylistList; +//class PlaylistList; +class PlaylistView; class PlaylistShade; class PlaylistMenu; + + +class PlaylistScrollBar : public QScrollBar { + Q_OBJECT + + public: + PlaylistScrollBar (QWidget *parent = NULL); + ~PlaylistScrollBar () {} + + public slots: + void mouseMoveEvent (QMouseEvent *event); + void mousePressEvent (QMouseEvent *event); + void mouseReleaseEvent (QMouseEvent *event); + void paintEvent (QPaintEvent *event); + void setPixmaps (Skin *skin); + + private: + int sliderPositionFromValue (); + int sliderValueFromPosition (int position); + + int m_sliderOffset; + QPixmap m_pixmap; + QPixmap m_slider; + QPixmap m_slider_down; +}; + + class dragButton : public Button { public: dragButton (QWidget *parent) : Button (parent) {} @@ -25,47 +54,6 @@ class dragButton : public Button { void mouseMoveEvent (QMouseEvent *event); }; -class PlaylistScrollButton : public Button { - public: - PlaylistScrollButton (PlaylistScroller *parent, uint normal, uint pressed); - ~PlaylistScrollButton () {} - private: - PlaylistScroller *m_slider; - void mouseMoveEvent (QMouseEvent *event); -}; - -class PlaylistScroller : public QWidget{ - Q_OBJECT - public: - PlaylistScroller (PlaylistWidget *arent); - ~PlaylistScroller () {} - void doScroll (void) { emit scrolled(getPos ()); } - - uint getPos (void); - uint getMax (void); - void setMax (uint max); - - void repositionButton (void); - - public slots: - void setPixmaps (Skin *skin); - - signals: - void scrolled (int); - - private: - void paintEvent (QPaintEvent *event); - QPixmap m_pixmap; - PlaylistScrollButton *m_button; - - uint m_max; -}; - -class PlaylistView : public QWidget { - public: - PlaylistView (QWidget *parent) : QWidget (parent) {} - ~PlaylistView () {} -}; class PlaylistWidget : public QWidget { Q_OBJECT @@ -76,12 +64,9 @@ class PlaylistWidget : public QWidget { void setActive (bool); void switchDisplay (void); - uint getOffset (void); public slots: void setPixmaps (Skin *skin); - void doScroll (int); - void sizeChangedList (QSize); void menuAddUrl () {} void menuAddDir (); @@ -110,8 +95,7 @@ class PlaylistWidget : public QWidget { bool m_active; PlaylistView *m_view; - PlaylistList *m_list; - PlaylistScroller *m_scroller; + QScrollBar *m_scrollBar; dragButton *m_drag; PlaylistMenu *m_add; @@ -145,12 +129,13 @@ class PlaylistWindow : public QMainWindow { private: PlaylistWidget *m_playlist; PlaylistShade *m_shaded; - + int m_diffx; int m_diffy; Button *m_shadebtn; Button *m_closebtn; + uint getOffset (void); MainWindow *m_mw; }; diff --git a/PlaylistList.cpp b/src/PlaylistList.cpp similarity index 100% rename from PlaylistList.cpp rename to src/PlaylistList.cpp diff --git a/PlaylistList.h b/src/PlaylistList.h similarity index 94% rename from PlaylistList.h rename to src/PlaylistList.h index 6ec0e71..0c82229 100644 --- a/PlaylistList.h +++ b/src/PlaylistList.h @@ -10,6 +10,12 @@ class PlaylistItem; +class PlaylistView : public QWidget { + public: + PlaylistView (QWidget *parent) : QWidget (parent) {} + ~PlaylistView () {} +}; + class PlaylistList : public QWidget { Q_OBJECT diff --git a/PlaylistMenu.cpp b/src/PlaylistMenu.cpp similarity index 100% rename from PlaylistMenu.cpp rename to src/PlaylistMenu.cpp diff --git a/PlaylistMenu.h b/src/PlaylistMenu.h similarity index 100% rename from PlaylistMenu.h rename to src/PlaylistMenu.h diff --git a/PlaylistShade.cpp b/src/PlaylistShade.cpp similarity index 100% rename from PlaylistShade.cpp rename to src/PlaylistShade.cpp diff --git a/PlaylistShade.h b/src/PlaylistShade.h similarity index 100% rename from PlaylistShade.h rename to src/PlaylistShade.h diff --git a/src/PlaylistView.cpp b/src/PlaylistView.cpp new file mode 100644 index 0000000..5169948 --- /dev/null +++ b/src/PlaylistView.cpp @@ -0,0 +1,221 @@ +// TODO might not need those +#include +#include "XMMSHandler.h" + +#include "PlaylistView.h" +#include "playlistmodel.h" +#include "Playlist.h" + +#include +#include +#include +#include +#include + +#include + +/* + * PlaylistDelegate + */ +PlaylistDelegate::PlaylistDelegate (QObject *parent) : + QAbstractItemDelegate (parent) +{ +} + +void +PlaylistDelegate::paint( QPainter *painter, const QStyleOptionViewItem& option, + const QModelIndex &index ) const +{ + painter->save (); + + /* Set background color */ + if ( option.state & QStyle::State_Selected ) { + qDrawPlainRect (painter, option.rect, QColor("#FFFFFF"), 0, + &option.palette.brush (QPalette::Highlight)); + } + + /* Set forground color */ + if ( index.data (PlaylistModel::CurrentEntryRole).toBool () ) { + painter->setPen (option.palette.brush (QPalette::BrightText).color ()); + } else { + painter->setPen (option.palette.brush (QPalette::Text).color ()); + } + + /* generate string */ + //TODO Add album and playtime + QVariant tmp; + QString s = QString ("%1. ").arg (index.row () + 1); + tmp = index.data (); + if (tmp.isValid ()) + s.append (tmp.toString ()).append (" - "); + QModelIndex m = index.sibling (index.row (), 1); + tmp = m.data (); + if (tmp.isValid ()) + s.append (tmp.toString ()); + s = option.fontMetrics.elidedText(s, Qt::ElideRight, option.rect.width()); + + painter->drawText (option.rect, Qt::AlignVCenter, s); + painter->restore (); +} + +QSize +PlaylistDelegate::sizeHint ( const QStyleOptionViewItem &option, + const QModelIndex &index ) const +{ + /* For QListModel, width must be > 0, but is otherwise */ + return QSize (1, option.font.pixelSize () +3); +} + + +/* + * PlaylistView + */ +//PlaylistView::PlaylistView (QWidget *parent) : QTableView (parent) +PlaylistView::PlaylistView (QWidget *parent) : QListView (parent) +{ + QSettings s; + Skin *skin = Skin::getInstance (); + + if (!s.contains ("playlist/fontsize")) + s.setValue ("playlist/fontsize", 10); + + setAttribute (Qt::WA_NoBackground); + // TODO make drag and drop work + //setDragEnabled(true); + //setAcceptDrops(true); + //setDropIndicatorShown (true); + // end DragandDrop + setFrameStyle(QFrame::NoFrame); + setFocusPolicy (Qt::StrongFocus); + setSelectionMode (QAbstractItemView::ExtendedSelection); + setUniformItemSizes(true); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + // TODO make sure delegate gets deleted + setItemDelegate (new PlaylistDelegate (this)); + + connect (skin, SIGNAL (skinChanged (Skin *)), + this, SLOT (setPixmaps(Skin *))); + + m_font = NULL; + m_fontmetrics = NULL; + + XMMSHandler &xmmsh = XMMSHandler::getInstance (); + + connect (&xmmsh, SIGNAL(settingsSaved()), + this, SLOT(settingsSaved())); + + connect (&xmmsh, SIGNAL(playbackStatusChanged(Xmms::Playback::Status)), + this, SLOT(handleStatus(Xmms::Playback::Status))); +} + +void +PlaylistView::setModel (QAbstractItemModel *model) { + QListView::setModel (model); + setModelColumn(0); + updateGeometry(); +} + +void +PlaylistView::contextMenuEvent (QContextMenuEvent *e) +{ + QMenu qm(this); + + QAction *a; + + a = new QAction (tr ("Show file info"), this); + a->setShortcut (tr ("Ctrl+Enter")); + // connect (a, SIGNAL (triggered ()), this, SLOT (showMlib ())); + qm.addAction (a); + qm.addSeparator (); + + a = new QAction (tr ("Add file"), this); + a->setShortcut (tr ("Ctrl+F")); + qm.addAction (a); + + a = new QAction (tr ("Remove selected"), this); + qm.addAction (a); + + qm.addSeparator (); + + a = new QAction (tr ("Medialib browser"), this); + qm.addAction (a); + + e->accept (); + qm.exec (e->globalPos ()); +} + +void +PlaylistView::handleStatus (const Xmms::Playback::Status st) +{ + m_status = st; +} + +void +PlaylistView::settingsSaved () +{ + QSettings s; + m_font->setPixelSize (s.value ("playlist/fontsize").toInt ()); + + if (m_fontmetrics) { + delete m_fontmetrics; + } + m_fontmetrics = new QFontMetrics (*m_font); + update (); +} + +void +PlaylistView::setPixmaps (Skin *skin) +{ + QSettings s; + QPalette pal; + QColor c; + c.setNamedColor (skin->getPLeditValue ("normalbg")); + QBrush b (c); + pal.setBrush (QPalette::Window, b); + setPalette (pal); + + if (m_font) { + delete m_font; + } + m_font = new QFont (skin->getPLeditValue ("font")); + m_font->setPixelSize (s.value ("playlist/fontsize").toInt ()); + + if (m_fontmetrics) { + delete m_fontmetrics; + } + m_fontmetrics = new QFontMetrics (*m_font); + + m_color_active.setNamedColor (skin->getPLeditValue ("current")); + m_color_selected.setNamedColor (skin->getPLeditValue ("selectedbg")); + m_color_normal.setNamedColor (skin->getPLeditValue ("normal")); + m_color_normal_bg.setNamedColor (skin->getPLeditValue ("normalbg")); + + // remove later, in here for testing + setFont(*m_font); + pal.setColor (QPalette::Text, m_color_normal); + pal.setColor (QPalette::BrightText, m_color_active); + pal.setColor (QPalette::Base, m_color_normal_bg); + pal.setColor (QPalette::Highlight, m_color_selected); + setPalette (pal); + + update (); +} + +void +PlaylistView::mouseDoubleClickEvent (QMouseEvent *event) +{ + QModelIndex index = indexAt(event->pos()); + if (!index.isValid()) { + return; + } + + XMMSHandler &xmmsh = XMMSHandler::getInstance (); + xmmsh.requestTrackChange (index.row()); + // TODO check for status first. + if (m_status == XMMS_PLAYBACK_STATUS_STOP || + m_status == XMMS_PLAYBACK_STATUS_PAUSE) { + xmmsh.play (); + } +} diff --git a/src/PlaylistView.h b/src/PlaylistView.h new file mode 100644 index 0000000..5b48da2 --- /dev/null +++ b/src/PlaylistView.h @@ -0,0 +1,57 @@ +#ifndef __PLAYLISTVIEW_H__ +#define __PLAYLISTVIEW_H__ + +//include "Playlist.h" +#include +#include "Skin.h" +#include +#include +#include +#include + +class PlaylistDelegate : public QAbstractItemDelegate { + Q_OBJECT + + public: + PlaylistDelegate (QObject *parent = NULL); + ~PlaylistDelegate () { } + + void paint( QPainter * painter, const QStyleOptionViewItem & option, + const QModelIndex & index ) const; + + QSize sizeHint ( const QStyleOptionViewItem &option, + const QModelIndex &index ) const; +}; + + +class PlaylistView : public QListView { + Q_OBJECT + + public: + PlaylistView (QWidget *parent); + ~PlaylistView () {} + + void setModel (QAbstractItemModel *model); + + public slots: + void contextMenuEvent (QContextMenuEvent *e); + + void handleStatus (const Xmms::Playback::Status st); + void settingsSaved (void); + void setPixmaps (Skin *skin); + + protected: + void mouseDoubleClickEvent (QMouseEvent *event); + + private: + Xmms::Playback::Status m_status; + QFont *m_font; + QFontMetrics *m_fontmetrics; + QColor m_color_active; + QColor m_color_selected; + QColor m_color_normal; + QColor m_color_normal_bg; +}; + + +#endif diff --git a/PosBar.cpp b/src/PosBar.cpp similarity index 100% rename from PosBar.cpp rename to src/PosBar.cpp diff --git a/PosBar.h b/src/PosBar.h similarity index 100% rename from PosBar.h rename to src/PosBar.h diff --git a/ServerBrowser.cpp b/src/ServerBrowser.cpp similarity index 100% rename from ServerBrowser.cpp rename to src/ServerBrowser.cpp diff --git a/ServerBrowser.h b/src/ServerBrowser.h similarity index 100% rename from ServerBrowser.h rename to src/ServerBrowser.h diff --git a/SettingsWindow.cpp b/src/SettingsWindow.cpp similarity index 100% rename from SettingsWindow.cpp rename to src/SettingsWindow.cpp diff --git a/SettingsWindow.h b/src/SettingsWindow.h similarity index 100% rename from SettingsWindow.h rename to src/SettingsWindow.h diff --git a/ShadedDisplay.cpp b/src/ShadedDisplay.cpp similarity index 92% rename from ShadedDisplay.cpp rename to src/ShadedDisplay.cpp index 68b6b09..6ef38a5 100644 --- a/ShadedDisplay.cpp +++ b/src/ShadedDisplay.cpp @@ -61,8 +61,8 @@ ShadedDisplay::ShadedDisplay (QWidget *parent) : SkinDisplay (parent) connect (&xmmsh, SIGNAL(playbackStatusChanged(Xmms::Playback::Status)), this, SLOT(setStatus(Xmms::Playback::Status))); - connect (&xmmsh, SIGNAL(playtimeChanged(uint)), - this, SLOT(setPlaytime(uint))); + connect (xmmsh.cache (), SIGNAL (playtime (uint32_t)), + this, SLOT ( setPlaytime(uint32_t))); connect (&xmmsh, SIGNAL(currentSong (const Xmms::PropDict &)), this, SLOT(setMediainfo (const Xmms::PropDict &))); } @@ -94,18 +94,15 @@ ShadedDisplay::setStatus (Xmms::Playback::Status status) } void -ShadedDisplay::setPlaytime (uint time) +ShadedDisplay::setPlaytime (uint32_t time) { uint sec, min; sec = (time / 1000) % 60; min = (time / 1000) / 60; - if (sec != m_number2->getNumber ()) { m_number2->setNumber (sec, 2); - } else if (min != m_number->getNumber ()) { m_number->setNumber (min, 2); - } } diff --git a/ShadedDisplay.h b/src/ShadedDisplay.h similarity index 94% rename from ShadedDisplay.h rename to src/ShadedDisplay.h index 7aaa471..5627156 100644 --- a/ShadedDisplay.h +++ b/src/ShadedDisplay.h @@ -32,7 +32,7 @@ class ShadedDisplay : public SkinDisplay public slots: void setStatus (Xmms::Playback::Status status); - void setPlaytime (uint time); + void setPlaytime (uint32_t time); void setMediainfo (const Xmms::PropDict &info); }; diff --git a/Skin.cpp b/src/Skin.cpp similarity index 99% rename from Skin.cpp rename to src/Skin.cpp index d2364e4..cdbc7f3 100644 --- a/Skin.cpp +++ b/src/Skin.cpp @@ -74,11 +74,11 @@ Skin::BuildPlaylist (void) m_playlist[PLS_VISMINI_0] = img->copy(205, 0, 75, 38); m_playlist[PLS_LFILL_0] = img->copy(0, 42, 12, 29); - + m_playlist[PLS_RFILL_0] = img->copy(31, 42, 5, 29); m_playlist[PLS_RFILL2_0] = img->copy(36, 42, 8, 29); m_playlist[PLS_RFILL3_0] = img->copy(44, 42, 7, 29); - + tmp = m_playlist[PLS_CORNER_UR_0]; m_playlist[PLS_CLOSE_BTN_0] = tmp.copy(14, 3, 9, 9); diff --git a/Skin.h b/src/Skin.h similarity index 100% rename from Skin.h rename to src/Skin.h diff --git a/SkinChooser.cpp b/src/SkinChooser.cpp similarity index 100% rename from SkinChooser.cpp rename to src/SkinChooser.cpp diff --git a/SkinChooser.h b/src/SkinChooser.h similarity index 100% rename from SkinChooser.h rename to src/SkinChooser.h diff --git a/SmallNumberDisplay.cpp b/src/SmallNumberDisplay.cpp similarity index 100% rename from SmallNumberDisplay.cpp rename to src/SmallNumberDisplay.cpp diff --git a/SmallNumberDisplay.h b/src/SmallNumberDisplay.h similarity index 100% rename from SmallNumberDisplay.h rename to src/SmallNumberDisplay.h diff --git a/StereoMono.cpp b/src/StereoMono.cpp similarity index 100% rename from StereoMono.cpp rename to src/StereoMono.cpp diff --git a/StereoMono.h b/src/StereoMono.h similarity index 100% rename from StereoMono.h rename to src/StereoMono.h diff --git a/TextBar.cpp b/src/TextBar.cpp similarity index 97% rename from TextBar.cpp rename to src/TextBar.cpp index 33c3e9c..d1a588b 100644 --- a/TextBar.cpp +++ b/src/TextBar.cpp @@ -69,8 +69,7 @@ void TextScroller::setPixmaps (Skin *skin) { QPalette pal = palette (); - QBrush b = QBrush (Qt::TexturePattern); - b.setTexture (skin->getItem (Skin::TEXTBG)); + QBrush b = QBrush (skin->getItem (Skin::TEXTBG)); pal.setBrush (QPalette::Window, b); setPalette (pal); diff --git a/TextBar.h b/src/TextBar.h similarity index 100% rename from TextBar.h rename to src/TextBar.h diff --git a/TimeDisplay.cpp b/src/TimeDisplay.cpp similarity index 96% rename from TimeDisplay.cpp rename to src/TimeDisplay.cpp index 1cad9c2..ff624af 100644 --- a/TimeDisplay.cpp +++ b/src/TimeDisplay.cpp @@ -65,8 +65,7 @@ TimeDisplay::drawMinus () Skin *skin = Skin::getInstance (); // Draw background - QBrush b (Qt::TexturePattern); - b.setTexture (skin->getNumber (10)); + QBrush b (skin->getNumber (10)); QPainter paint; paint.begin (&m_pixmap); diff --git a/TimeDisplay.h b/src/TimeDisplay.h similarity index 100% rename from TimeDisplay.h rename to src/TimeDisplay.h diff --git a/TitleBar.cpp b/src/TitleBar.cpp similarity index 100% rename from TitleBar.cpp rename to src/TitleBar.cpp diff --git a/TitleBar.h b/src/TitleBar.h similarity index 100% rename from TitleBar.h rename to src/TitleBar.h diff --git a/VolumeSlider.cpp b/src/VolumeSlider.cpp similarity index 100% rename from VolumeSlider.cpp rename to src/VolumeSlider.cpp diff --git a/VolumeSlider.h b/src/VolumeSlider.h similarity index 100% rename from VolumeSlider.h rename to src/VolumeSlider.h diff --git a/XMMSHandler.cpp b/src/XMMSHandler.cpp similarity index 67% rename from XMMSHandler.cpp rename to src/XMMSHandler.cpp index 5b7ecc6..2cd1aea 100644 --- a/XMMSHandler.cpp +++ b/src/XMMSHandler.cpp @@ -1,7 +1,8 @@ #include -#include "XmmsQT4.h" +#include "xmmsqt4.h" #include "XMMSHandler.h" +#include "playlistmodel.h" #include #include @@ -18,27 +19,24 @@ static bool log ( /*const std::string& text = ""*/ ) return false; } -static bool logUint ( const unsigned int & /*, const std::string& text = "" */ ) -{ - return false; -} - XMMSHandler &XMMSHandler::getInstance () { - static XMMSHandler singleton; + static XMMSHandler singleton(NULL, "Prome_Main"); return singleton; } -XMMSHandler::XMMSHandler () : QObject (), m_client ("Prome_Main") +XMMSHandler::XMMSHandler (QObject *parent, const std::string &name) : XClient (parent, name) { - connect (std::getenv ( "XMMS_PATH" )); + connect_handler(); } bool -XMMSHandler::connect (const char *path) +XMMSHandler::connect_handler (const char *ipcpath, const bool &sync, QWidget *parent) { - try { - m_client.connect (path ? path : ""); +/* try { + m_client.connect(path); + //TODO reenable checking of path + //m_client.connect (path ? path : ""); } catch (Xmms::connection_error& e) { QErrorMessage *err = new QErrorMessage (); @@ -49,30 +47,30 @@ XMMSHandler::connect (const char *path) } m_client.setMainloop (new XmmsQT4 (m_client.getConnection ())); +*/ + //TODO must be moved elsewere later + m_playlist_model = new PlaylistModel(NULL, this, "_active"); + + connect(ipcpath, sync, parent); using Xmms::bind; - m_client.playlist.list (bind (&XMMSHandler::playlist_list, this)); - m_client.playlist.broadcastChanged ( - bind (&XMMSHandler::playlist_changed, this)); +// m_client->playlist.listEntries () (bind (&XMMSHandler::playlist_list, this)); +// m_client->playlist.broadcastChanged () (bind (&XMMSHandler::playlist_changed, this)); - m_client.medialib.broadcastEntryChanged ( - bind (&XMMSHandler::medialib_entry_changed, this)); + m_client->medialib.broadcastEntryChanged () (bind (&XMMSHandler::medialib_entry_changed, this)); - m_client.playback.currentID ( - bind (&XMMSHandler::playback_current_id, this)); - m_client.playback.broadcastCurrentID ( - bind (&XMMSHandler::playback_current_id, this)); + m_client->playback.currentID () (bind (&XMMSHandler::playback_current_id, this)); + m_client->playback.broadcastCurrentID () (bind (&XMMSHandler::playback_current_id, this)); - m_client.playback.getStatus (bind (&XMMSHandler::playback_status, this)); - m_client.playback.broadcastStatus ( - bind (&XMMSHandler::playback_status, this)); + m_client->playback.getStatus () (bind (&XMMSHandler::playback_status, this)); + m_client->playback.broadcastStatus () (bind (&XMMSHandler::playback_status, this)); - m_client.playback.broadcastVolumeChanged ( - bind (&XMMSHandler::volume_changed, this)); + m_client->playback.broadcastVolumeChanged () (bind (&XMMSHandler::volume_changed, this)); - QObject::connect (&m_playtime_timer, SIGNAL (timeout ()), - this, SLOT (restartPlaytime ())); - m_playtime_timer.start(0); + // TODO: Disabled for now. Seems to cause problems on startup +// QObject::connect (&m_playtime_timer, SIGNAL (timeout ()), +// this, SLOT (restartPlaytime ())); +// m_playtime_timer.start(0); return true; } @@ -81,14 +79,13 @@ XMMSHandler::connect (const char *path) Xmms::Client * XMMSHandler::getClient () { - return &m_client; + return m_client; } void XMMSHandler::restartPlaytime () { - m_client.playback.getPlaytime (Xmms::bind (&XMMSHandler::playback_playtime, - this)); + m_client->playback.getPlaytime () (Xmms::bind (&XMMSHandler::playback_playtime, this)); } bool @@ -103,38 +100,37 @@ XMMSHandler::medialib_entry_changed (const unsigned int &id) void XMMSHandler::playlistAddURL (const QString &s) { - m_client.playlist.addUrl (s.toAscii ().constData (), &log); + m_client->playlist.addUrl (s.toAscii ().constData ()) (); } void XMMSHandler::playlistRemove (uint pos) { - m_client.playlist.remove (pos, &log); + m_client->playlist.removeEntry (pos) (); } void XMMSHandler::playlistMove (uint pos, uint newpos) { - m_client.playlist.move (pos, newpos, &log); + m_client->playlist.moveEntry (pos, newpos) (); } void XMMSHandler::requestMediainfo (uint id) { - m_client.medialib.getInfo (id, - Xmms::bind (&XMMSHandler::medialib_info, this)); + m_client->medialib.getInfo (id) (Xmms::bind (&XMMSHandler::medialib_info, this)); } void XMMSHandler::requestPlaylistList () { - m_client.playlist.list (Xmms::bind (&XMMSHandler::playlist_list, this)); +// m_client->playlist.listEntries () (Xmms::bind (&XMMSHandler::playlist_list, this)); } void XMMSHandler::requestTrackChange (int pos) { - m_client.playlist.setNext (pos, &logUint); - m_client.playback.tickle (&log); + m_client->playlist.setNext (pos) (); + m_client->playback.tickle () (); } bool @@ -175,7 +171,7 @@ XMMSHandler::playback_current_id (const unsigned int &id) void XMMSHandler::setPlaytime (uint pos) { - m_client.playback.seekMs (pos, &log); + m_client->playback.seekMs (pos) (); } void @@ -265,7 +261,7 @@ XMMSHandler::volume_error (const std::string &error) void XMMSHandler::volumeGet () { - m_client.playback.volumeGet (Xmms::bind (&XMMSHandler::volume_get, this), + m_client->playback.volumeGet () (Xmms::bind (&XMMSHandler::volume_get, this), Xmms::bind (&XMMSHandler::volume_error, this)); } @@ -274,12 +270,12 @@ XMMSHandler::volumeSet (uint volume) { if(m_masterchan) { - m_client.playback.volumeSet ("master", volume, &log); + m_client->playback.volumeSet ("master", volume) (); } else { - m_client.playback.volumeSet ("left", volume, &log); - m_client.playback.volumeSet ("right", volume, &log); + m_client->playback.volumeSet ("left", volume) (); + m_client->playback.volumeSet ("right", volume) (); } } @@ -323,33 +319,33 @@ XMMSHandler::volume_get (const Xmms::Dict &levels) void XMMSHandler::playlistClear () { - m_client.playlist.clear (&log); + m_client->playlist.clear () (); } void XMMSHandler::play () { - m_client.playback.start (&log); + m_client->playback.start () (); } void XMMSHandler::stop () { - m_client.playback.stop (&log); + m_client->playback.stop () (); } void XMMSHandler::pause () { - m_client.playback.pause (&log); + m_client->playback.pause () (); } void XMMSHandler::next () { - m_client.playlist.setNextRel (1, &logUint); - m_client.playback.tickle (&log); + m_client->playlist.setNextRel (1) (); + m_client->playback.tickle () (); } void XMMSHandler::prev () { - m_client.playlist.setNextRel (-1, &logUint); - m_client.playback.tickle (&log); + m_client->playlist.setNextRel (-1) (); + m_client->playback.tickle () (); } diff --git a/XMMSHandler.h b/src/XMMSHandler.h similarity index 85% rename from XMMSHandler.h rename to src/XMMSHandler.h index 473debf..9ec2391 100644 --- a/XMMSHandler.h +++ b/src/XMMSHandler.h @@ -3,18 +3,24 @@ #include -#include "XmmsQT4.h" +#include "xclient.h" +#include "xmmsqt4.h" #include #include #include -class XMMSHandler : public QObject { +class PlaylistModel; + +class XMMSHandler : public XClient { Q_OBJECT public: static XMMSHandler &getInstance (); - bool connect (const char *path); + XMMSHandler (QObject *parent, const std::string &name); + ~XMMSHandler () {}; + + bool connect_handler (const char *ipcpath = NULL, const bool &sync = false, QWidget *parent = NULL); bool playback_playtime (const unsigned int &time); bool playlist_list (const Xmms::List< unsigned int > &playlist); @@ -50,6 +56,8 @@ class XMMSHandler : public QObject { Xmms::Client *getClient (); + PlaylistModel *getPlaylistModel () {return m_playlist_model; } + public slots: void setPlaytime (uint pos); void restartPlaytime (); @@ -79,12 +87,10 @@ class XMMSHandler : public QObject { private: QTimer m_playtime_timer; - XMMSHandler (); - ~XMMSHandler () {}; void DictToQHash (const std::string &key, const Xmms::Dict::Variant &value, QHash &hash); - void PropDictToQHash (const std::string &key, + void PropDictToQHash (const std::string &key, const Xmms::Dict::Variant &value, const std::string &source, QHash &hash); @@ -92,8 +98,8 @@ class XMMSHandler : public QObject { bool volume_get (const Xmms::Dict &levels); bool volume_error (const std::string &error); - Xmms::Client m_client; XmmsQT4 *m_qt4; + PlaylistModel *m_playlist_model; unsigned int m_currentid; bool m_masterchan; }; diff --git a/avahi.prf b/src/avahi.prf similarity index 100% rename from avahi.prf rename to src/avahi.prf diff --git a/icon.png b/src/icon.png similarity index 100% rename from icon.png rename to src/icon.png diff --git a/noalbum.png b/src/noalbum.png similarity index 100% rename from noalbum.png rename to src/noalbum.png diff --git a/noartist.png b/src/noartist.png similarity index 100% rename from noartist.png rename to src/noartist.png diff --git a/nocover.png b/src/nocover.png similarity index 100% rename from nocover.png rename to src/nocover.png diff --git a/nosong.png b/src/nosong.png similarity index 100% rename from nosong.png rename to src/nosong.png diff --git a/promoe.qrc b/src/promoe.qrc similarity index 100% rename from promoe.qrc rename to src/promoe.qrc diff --git a/qtmd5.cpp b/src/qtmd5.cpp similarity index 100% rename from qtmd5.cpp rename to src/qtmd5.cpp diff --git a/qtmd5.h b/src/qtmd5.h similarity index 100% rename from qtmd5.h rename to src/qtmd5.h diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..e424a62 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,89 @@ +TEMPLATE = app + +include (../config.pri) + +COMPONENTS+=../lib/liblib.a +LIBS += $$COMPONENTS +PRE_TARGETDEPS = $$COMPONENTS + +SOURCES += PixWidget.cpp \ + Skin.cpp \ + MainWindow.cpp \ + Display.cpp \ + MainDisplay.cpp \ + TitleBar.cpp \ + Button.cpp \ + TextBar.cpp \ + NumberDisplay.cpp \ + TimeDisplay.cpp \ + XMMSHandler.cpp \ + SmallNumberDisplay.cpp \ + StereoMono.cpp \ + PosBar.cpp \ + PlayStatus.cpp \ + ShadedDisplay.cpp \ + Playlist.cpp \ + PlaylistView.cpp \ + SkinChooser.cpp \ + PlaylistShade.cpp \ + qtmd5.cpp \ + SettingsWindow.cpp \ + PlaylistMenu.cpp \ + VolumeSlider.cpp \ + ClutterBar.cpp \ + Equalizer.cpp \ + FileDialog.cpp \ + BrowseModel.cpp \ + BrowseDialog.cpp + + +HEADERS += PixWidget.h \ + Skin.h \ + MainWindow.h \ + Display.h \ + MainDisplay.h \ + TitleBar.h \ + Button.h \ + TextBar.h \ + NumberDisplay.h \ + TimeDisplay.h \ + XMMSHandler.h \ + SmallNumberDisplay.h \ + StereoMono.h \ + PosBar.h \ + PlayStatus.h \ + ShadedDisplay.h \ + Playlist.h \ + PlaylistView.h \ + SkinChooser.h \ + PlaylistShade.h \ + qtmd5.h \ + SettingsWindow.h \ + PlaylistMenu.h \ + VolumeSlider.h \ + ClutterBar.h \ + Equalizer.h \ + FileDialog.h \ + BrowseModel.h \ + BrowseDialog.h + +TARGET = promoe +DESTDIR = $$PWD/.. + +RESOURCES = promoe.qrc +macx:RC_FILE = promoe.icns +macx:INCLUDEPATH = /sw/include + +QT += network +;macx:QTPLUGIN += qjpeg +QMAKE_LFLAGS += -L$$[QT_INSTALL_PLUGINS]/imageformats + +CONFIG += link_pkgconfig + +QMAKE_CXXFLAGS += -g +;CONFIG += debug warn_on +QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter +PKGCONFIG += xmms2-client xmms2-client-cpp + +;CONFIG += avahi + diff --git a/xmmsclient_methods.h b/src/xmmsclient_methods.h similarity index 100% rename from xmmsclient_methods.h rename to src/xmmsclient_methods.h diff --git a/xmmsclient_promoe.cpp b/src/xmmsclient_promoe.cpp similarity index 100% rename from xmmsclient_promoe.cpp rename to src/xmmsclient_promoe.cpp diff --git a/xmmsclient_promoe.h b/src/xmmsclient_promoe.h similarity index 100% rename from xmmsclient_promoe.h rename to src/xmmsclient_promoe.h