From 6d271f221c29d42e96b0d8c34fc0d0623a8f30eb Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Sun, 1 Mar 2009 15:22:11 +0100 Subject: [PATCH] OTHER: Update to c++ iterators and uint remove --- lib/playlistmodel.cpp | 24 ++++++++++++++++++++++++ lib/playlistmodel.h | 7 ++++++- lib/xcollection.cpp | 8 ++++++++ src/BrowseModel.cpp | 7 +++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/playlistmodel.cpp b/lib/playlistmodel.cpp index 515654c..5ee318a 100644 --- a/lib/playlistmodel.cpp +++ b/lib/playlistmodel.cpp @@ -16,6 +16,7 @@ #include +#include "compat.h" #include #include #include @@ -119,7 +120,11 @@ PlaylistModel::handle_update_pos (const Xmms::Dict &posdict) { QString changed_pl = XClient::stdToQ (posdict.get ("name")); if (changed_pl == m_name) { +#if HAVE_XMMSV + uint32_t pos = posdict.get ("position"); +#else uint32_t pos = posdict.get ("position"); +#endif m_current_pos = pos; emit currentPosChanged (index (pos, 0)); emit dataChanged(index (pos, 0), index (pos, m_columns.size ())); @@ -231,21 +236,40 @@ PlaylistModel::handle_change (const Xmms::Dict &chg) return true; } +#if HAVE_XMMSV +bool +PlaylistModel::handle_list (const Xmms::List< int > &list) +#else bool PlaylistModel::handle_list (const Xmms::List< unsigned int > &list) +#endif { beginRemoveRows (QModelIndex (), 0, m_plist.size ()); m_plist.clear (); endRemoveRows (); int i = 0; +#if HAVE_XMMSV + for (Xmms::List< int >::const_iterator iter = list.begin(); + iter != list.end(); iter ++) { + i++; + } +#else for (list.first (); list.isValid (); ++list) { i ++; } +#endif beginInsertRows (QModelIndex (), 0, i); +#if HAVE_XMMSV + for (Xmms::List< int >::const_iterator iter = list.begin(); + iter != list.end(); iter ++) { + m_plist.append (*iter); + } +#else for (list.first (); list.isValid (); ++list) { m_plist.append (*list); } +#endif endInsertRows (); diff --git a/lib/playlistmodel.h b/lib/playlistmodel.h index ef70000..fbc45ac 100644 --- a/lib/playlistmodel.h +++ b/lib/playlistmodel.h @@ -19,6 +19,7 @@ #define __PLAYLIST_MODEL_H__ #include +#include "compat.h" class XClient; @@ -123,7 +124,7 @@ class PlaylistModel : public QAbstractItemModel QList < uint32_t > getPosById (uint32_t id); QList < QString > m_columns; QList < QString > m_colfallback; - + signals: void entryMoved (const QModelIndex &, const QModelIndex &); void currentPosChanged (QModelIndex); @@ -134,7 +135,11 @@ class PlaylistModel : public QAbstractItemModel void entry_changed (uint32_t); private: +#if HAVE_XMMSV + bool handle_list (const Xmms::List< int > &list); +#else bool handle_list (const Xmms::List< unsigned int > &list); +#endif bool handle_change (const Xmms::Dict &chg); #if (XMMS_IPC_PROTOCOL_VERSION > 10) bool handle_update_pos (const Xmms::Dict &pos); diff --git a/lib/xcollection.cpp b/lib/xcollection.cpp index a197ed8..aeab312 100644 --- a/lib/xcollection.cpp +++ b/lib/xcollection.cpp @@ -14,6 +14,7 @@ */ #include +#include "compat.h" #include "xcollection.h" #include "xcollection_p.h" @@ -163,9 +164,16 @@ XCollection::Private::handle_playlists_list (const Xmms::List< std::string > &li { m_playlists.clear (); +#if HAVE_XMMSV + for (Xmms::List< std::string >::const_iterator iter = list.begin(); + iter != list.end(); iter ++) { + m_playlists.append (XClient::stdToQ(*iter)); + } +#else for (list.first (); list.isValid (); ++list) { m_playlists.append (XClient::stdToQ(*list)); } +#endif m_playlists.sort (); return true; diff --git a/src/BrowseModel.cpp b/src/BrowseModel.cpp index 101bdb1..2501ee9 100644 --- a/src/BrowseModel.cpp +++ b/src/BrowseModel.cpp @@ -14,6 +14,7 @@ */ #include "xclient.h" +#include "compat.h" #include "BrowseModel.h" #include "application.h" @@ -100,8 +101,14 @@ BrowseModel::list_cb (const Xmms::List< Xmms::Dict > &res) delete m_list.takeFirst (); } +#if HAVE_XMMSV + for (Xmms::List< Xmms::Dict >::const_iterator iter = res.begin(); + iter != res.end(); iter++) { + Xmms::Dict d = *iter; +#else for (res.first (); res.isValid (); ++res) { Xmms::Dict d = *res; +#endif if (!d.contains ("path")) continue;