Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cleanup and UI fixes. #167

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "backend/lib/noson"]
path = backend/lib/noson
url = https://github.com/janbar/noson.git
16 changes: 11 additions & 5 deletions backend/NosonApp/listmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
#include <QObject>
#include <QRunnable>

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#include <QRecursiveMutex>
#endif

Q_DECLARE_METATYPE(SONOS::DigitalItemPtr)
Q_DECLARE_METATYPE(SONOS::ZonePtr)
Q_DECLARE_METATYPE(SONOS::ZonePlayerPtr)
Q_DECLARE_METATYPE(SONOS::SMServicePtr)
Q_DECLARE_METATYPE(SONOS::AlarmPtr)

#define USE_RECURSIVE_MUTEX

namespace nosonapp
{

Expand Down Expand Up @@ -82,10 +84,10 @@ class ListModel
, m_dataState(DataBlank)
, m_updateSignaled(false)
{
#ifdef USE_RECURSIVE_MUTEX
m_lock = new QMutex(QMutex::Recursive);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
m_lock = new QRecursiveMutex;
#else
m_lock = new QMutex();
m_lock = new QMutex(QMutex::Recursive);
#endif
}

Expand All @@ -112,7 +114,11 @@ class ListModel

public:
T* m_provider;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QRecursiveMutex* m_lock;
#else
QMutex* m_lock;
#endif
unsigned m_updateID;
QString m_root;
bool m_pending;
Expand Down
26 changes: 26 additions & 0 deletions backend/NosonApp/locked.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
#ifndef NOSONAPPLOCKED_H
#define NOSONAPPLOCKED_H

#include <QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#include <QRecursiveMutex>
#else
#include <QMutex>
#endif

namespace nosonapp
{
Expand All @@ -35,7 +40,12 @@ class LockGuard
* destructor.
* @param lock The pointer to lockable object
*/

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
LockGuard(QRecursiveMutex * lock)
#else
LockGuard(QMutex * lock)
#endif
: m_lock(lock)
{
if (m_lock)
Expand All @@ -61,7 +71,11 @@ class LockGuard
}

private:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QRecursiveMutex * m_lock;
#else
QMutex * m_lock;
#endif
};

template<typename T>
Expand All @@ -70,7 +84,11 @@ class Locked
public:
Locked(const T& val)
: m_val(val)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
, m_lock(new QRecursiveMutex) {}
#else
, m_lock(new QMutex(QMutex::Recursive)) {}
#endif

~Locked()
{
Expand All @@ -93,7 +111,11 @@ class Locked
class pointer
{
public:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
pointer(T& val, QRecursiveMutex*& lock) : m_val(val), m_g(lock) {}
#else
pointer(T& val, QMutex*& lock) : m_val(val), m_g(lock) {}
#endif
T& operator* () const { return m_val; }
T *operator->() const { return &m_val; }
private:
Expand All @@ -108,7 +130,11 @@ class Locked

protected:
T m_val;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QRecursiveMutex * m_lock;
#else
QMutex * m_lock;
#endif

// Prevent copy
Locked(const Locked<T>& other);
Expand Down
16 changes: 8 additions & 8 deletions backend/NosonMediaScanner/aggregate/albums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Albums::~Albums()
void Albums::addItem(ItemPtr& item)
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_items << item;
endInsertRows();
Expand All @@ -63,7 +63,7 @@ void Albums::addItem(ItemPtr& item)
void Albums::removeItem(const QByteArray& id)
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
int row = 0;
for (const ItemPtr& item : m_items)
{
Expand All @@ -83,13 +83,13 @@ void Albums::removeItem(const QByteArray& id)
int Albums::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
return m_items.count();
}

QVariant Albums::data(const QModelIndex& index, int role) const
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (index.row() < 0 || index.row() >= m_items.count())
return QVariant();

Expand Down Expand Up @@ -123,7 +123,7 @@ QVariant Albums::data(const QModelIndex& index, int role) const

bool Albums::setData(const QModelIndex &index, const QVariant &value, int role)
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (index.row() < 0 || index.row() >= m_items.count())
return false;

Expand Down Expand Up @@ -152,7 +152,7 @@ QHash<int, QByteArray> Albums::roleNames() const

QVariantMap Albums::get(int row)
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (row < 0 || row >= m_items.count())
return QVariantMap();
const ItemPtr item = m_items[row];
Expand All @@ -173,7 +173,7 @@ QVariantMap Albums::get(int row)

void Albums::clear()
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (m_dataState == ListModel::New)
return;
if (m_items.count() > 0)
Expand All @@ -188,7 +188,7 @@ void Albums::clear()
bool Albums::load()
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
beginResetModel();
clear();

Expand Down
16 changes: 8 additions & 8 deletions backend/NosonMediaScanner/aggregate/artists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Artists::~Artists()
void Artists::addItem(ItemPtr& item)
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_items << item;
endInsertRows();
Expand All @@ -60,7 +60,7 @@ void Artists::addItem(ItemPtr& item)
void Artists::removeItem(const QByteArray& id)
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
int row = 0;
for (const ItemPtr& item : m_items)
{
Expand All @@ -80,13 +80,13 @@ void Artists::removeItem(const QByteArray& id)
int Artists::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
return m_items.count();
}

QVariant Artists::data(const QModelIndex& index, int role) const
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (index.row() < 0 || index.row() >= m_items.count())
return QVariant();

Expand All @@ -112,7 +112,7 @@ QVariant Artists::data(const QModelIndex& index, int role) const

bool Artists::setData(const QModelIndex &index, const QVariant &value, int role)
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (index.row() < 0 || index.row() >= m_items.count())
return false;

Expand All @@ -136,7 +136,7 @@ QHash<int, QByteArray> Artists::roleNames() const

QVariantMap Artists::get(int row)
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (row < 0 || row >= m_items.count())
return QVariantMap();
const ItemPtr item = m_items[row];
Expand All @@ -153,7 +153,7 @@ QVariantMap Artists::get(int row)

void Artists::clear()
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (m_dataState == ListModel::New)
return;
if (m_items.count() > 0)
Expand All @@ -168,7 +168,7 @@ void Artists::clear()
bool Artists::load()
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
beginResetModel();
clear();

Expand Down
16 changes: 8 additions & 8 deletions backend/NosonMediaScanner/aggregate/composers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Composers::~Composers()
void Composers::addItem(ItemPtr& item)
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_items << item;
endInsertRows();
Expand All @@ -60,7 +60,7 @@ void Composers::addItem(ItemPtr& item)
void Composers::removeItem(const QByteArray& id)
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
int row = 0;
for (const ItemPtr& item : m_items)
{
Expand All @@ -80,13 +80,13 @@ void Composers::removeItem(const QByteArray& id)
int Composers::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
return m_items.count();
}

QVariant Composers::data(const QModelIndex& index, int role) const
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (index.row() < 0 || index.row() >= m_items.count())
return QVariant();

Expand All @@ -112,7 +112,7 @@ QVariant Composers::data(const QModelIndex& index, int role) const

bool Composers::setData(const QModelIndex &index, const QVariant &value, int role)
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (index.row() < 0 || index.row() >= m_items.count())
return false;

Expand All @@ -136,7 +136,7 @@ QHash<int, QByteArray> Composers::roleNames() const

QVariantMap Composers::get(int row)
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (row < 0 || row >= m_items.count())
return QVariantMap();
const ItemPtr item = m_items[row];
Expand All @@ -153,7 +153,7 @@ QVariantMap Composers::get(int row)

void Composers::clear()
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
if (m_dataState == ListModel::New)
return;
if (m_items.count() > 0)
Expand All @@ -168,7 +168,7 @@ void Composers::clear()
bool Composers::load()
{
{
LockGuard lock(m_lock);
QMutexLocker lock(m_lock);
beginResetModel();
clear();

Expand Down
Loading