mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2024-11-24 02:05:16 +00:00
Add basic settings framework
This settingsframework uses mlite5 on SailfishOS and other platforms with the mlite library present, because I believe DConf is neat. For platforms that do not have DConf and mlite present, it falls back to a quickly put together implementation that uses QSettings as a backend. Implementing an settings item is simply done by subclassing the Jellyfin::QObjectSettingsWrapper.
This commit is contained in:
parent
a89834044c
commit
1453cbbc63
|
@ -11,6 +11,7 @@ option(PLATFORM_SAILFISHOS "Build SailfishOS version of application" OFF)
|
|||
option(PLATFORM_QTQUICK "Build QtQuick version of application" ON)
|
||||
option(FREEDESKTOP_INTEGRATION "Integration with various FreeDesktop.org standards, such as MPRIS" ON)
|
||||
option(BUILD_PRECOMPILED_HEADERS "Build with precompiled headers for faster compile times when doing a full rebuild, at the cost of slower incremental builds whenever a header file is changed" OFF)
|
||||
option(USE_MLITE "Build with mlite (MeeGo lite library), only available on Linux-based platforms. Used to store settings using DConf." OFF)
|
||||
|
||||
if (NOT SAILFIN_VERSION)
|
||||
set(SAILFIN_VERSION "1.0.0")
|
||||
|
@ -19,6 +20,7 @@ endif()
|
|||
if(PLATFORM_SAILFISHOS)
|
||||
# Hardcode this less?
|
||||
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/share/harbour-sailfin/lib")
|
||||
set(USE_MLITE ON)
|
||||
endif()
|
||||
|
||||
add_subdirectory(core)
|
||||
|
|
39
cmake/Findmlite5.cmake
Normal file
39
cmake/Findmlite5.cmake
Normal file
|
@ -0,0 +1,39 @@
|
|||
# - Try to find mlite5
|
||||
# Once done this will define
|
||||
# mlite5_FOUND - System has mlite5
|
||||
# mlite5_INCLUDE_DIRS - The mlite5 include directories
|
||||
# mlite5_LIBRARIES - The libraries needed to use mlite5
|
||||
# mlite5_DEFINITIONS - Compiler switches required for using mlite5
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_mlite5 QUIET mlite5)
|
||||
set(mlite5_DEFINITIONS ${PC_mlite5_CFLAGS_OTHER})
|
||||
|
||||
find_path(mlite5_INCLUDE_DIR mlite-global.h
|
||||
HINTS ${PC_mlite5_INCLUDEDIR} ${PC_mlite5_INCLUDE_DIRS}
|
||||
PATH_SUFFIXES sailfishapp )
|
||||
|
||||
find_library(mlite5_LIBRARY NAMES mlite5 mlite libmlite libmlite5
|
||||
HINTS ${PC_mlite5_LIBDIR} ${PC_mlite5_LIBRARY_DIRS} )
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
# handle the QUIETLY and REQUIRED arguments and set LIBmlite5_FOUND to TRUE
|
||||
# if all listed variables are TRUE
|
||||
set(mlite5_VERSION ${PC_mlite5_VERSION})
|
||||
find_package_handle_standard_args(mlite5
|
||||
FOUND_VAR mlite5_FOUND
|
||||
REQUIRED_VARS
|
||||
mlite5_LIBRARY
|
||||
mlite5_INCLUDE_DIR
|
||||
VERSION_VAR mlite5_VERSION)
|
||||
|
||||
if(mlite5_FOUND AND NOT TARGET Foo::Foo)
|
||||
add_library(mlite5::mlite5 UNKNOWN IMPORTED)
|
||||
set_target_properties(mlite5::mlite5 PROPERTIES
|
||||
IMPORTED_LOCATION "${mlite5_LIBRARY}"
|
||||
INTERFACE_COMPILE_OPTIONS "${PC_mlite5_CFLAGS_OTHER}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${mlite5_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(mlite5_INCLUDE_DIR mlite5_LIBRARY )
|
|
@ -2,14 +2,17 @@ project(jellyfin-qt VERSION 0.1.0)
|
|||
find_package(Qt5 5.6 COMPONENTS Multimedia Network Qml WebSockets REQUIRED)
|
||||
|
||||
if (FREEDESKTOP_INTEGRATION)
|
||||
find_package(Qt5 5.6 COMPONENTS DBus REQUIRED)
|
||||
find_package(Qt5 5.6 COMPONENTS DBus REQUIRED)
|
||||
endif()
|
||||
|
||||
if (USE_MLITE)
|
||||
find_package(mlite5 REQUIRED)
|
||||
endif()
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(GeneratedSources.cmake)
|
||||
|
||||
set(JellyfinQt_SOURCES
|
||||
# src/DTO/dto.cpp
|
||||
src/model/deviceprofile.cpp
|
||||
src/model/item.cpp
|
||||
src/model/playlist.cpp
|
||||
|
@ -26,6 +29,7 @@ set(JellyfinQt_SOURCES
|
|||
src/viewmodel/modelstatus.cpp
|
||||
src/viewmodel/playbackmanager.cpp
|
||||
src/viewmodel/playlist.cpp
|
||||
src/viewmodel/settings.cpp
|
||||
src/viewmodel/userdata.cpp
|
||||
src/viewmodel/usermodel.cpp
|
||||
src/viewmodel/user.cpp
|
||||
|
@ -35,6 +39,7 @@ set(JellyfinQt_SOURCES
|
|||
src/eventbus.cpp
|
||||
src/jellyfin.cpp
|
||||
src/jsonhelper.cpp
|
||||
src/qobjectsettingswrapper.cpp
|
||||
src/serverdiscoverymodel.cpp
|
||||
src/websocket.cpp)
|
||||
|
||||
|
@ -59,6 +64,7 @@ set(JellyfinQt_HEADERS
|
|||
include/JellyfinQt/viewmodel/playbackmanager.h
|
||||
include/JellyfinQt/viewmodel/platformmediacontrol.h
|
||||
include/JellyfinQt/viewmodel/playlist.h
|
||||
include/JellyfinQt/viewmodel/settings.h
|
||||
include/JellyfinQt/viewmodel/userdata.h
|
||||
include/JellyfinQt/viewmodel/usermodel.h
|
||||
include/JellyfinQt/viewmodel/user.h
|
||||
|
@ -68,6 +74,7 @@ set(JellyfinQt_HEADERS
|
|||
include/JellyfinQt/eventbus.h
|
||||
include/JellyfinQt/jellyfin.h
|
||||
include/JellyfinQt/jsonhelper.h
|
||||
include/JellyfinQt/qobjectsettingswrapper.h
|
||||
include/JellyfinQt/serverdiscoverymodel.h
|
||||
include/JellyfinQt/websocket.h)
|
||||
|
||||
|
@ -92,6 +99,8 @@ if (PLATFORM_SAILFISHOS)
|
|||
add_definitions(-DPLATFORM_SAILFISHOS=1)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
add_library(JellyfinQt ${JellyfinQt_SOURCES} ${JellyfinQt_HEADERS})
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_GREATER "3.16.0")
|
||||
|
@ -106,6 +115,12 @@ target_link_libraries(JellyfinQt PUBLIC Qt5::Core Qt5::Multimedia Qt5::Network Q
|
|||
if (FREEDESKTOP_INTEGRATION)
|
||||
target_link_libraries(JellyfinQt PUBLIC Qt5::DBus)
|
||||
endif()
|
||||
|
||||
if (USE_MLITE)
|
||||
add_definitions(-DUSE_MLITE)
|
||||
target_link_libraries(JellyfinQt PUBLIC mlite5::mlite5)
|
||||
endif()
|
||||
|
||||
set_target_properties(JellyfinQt PROPERTIES CXX_VISIBILITY_PRESET default)
|
||||
install(TARGETS JellyfinQt
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
|
|
100
core/include/JellyfinQt/qobjectsettingswrapper.h
Normal file
100
core/include/JellyfinQt/qobjectsettingswrapper.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Sailfin: a Jellyfin client written using Qt
|
||||
* Copyright (C) 2021 Chris Josten and the Sailfin Contributors
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef JELLYFIN_QOBJECTSETTINGSWRAPPER_H
|
||||
#define JELLYFIN_QOBJECTSETTINGSWRAPPER_H
|
||||
|
||||
|
||||
#if USE_MLITE
|
||||
#include <MDConfGroup>
|
||||
namespace Jellyfin {
|
||||
using QObjectSettingsWrapper = MDConfGroup;
|
||||
} // NS Jellyfin
|
||||
#else
|
||||
|
||||
/***************************************************************************
|
||||
** Copyright (C) 2014 Jolla Mobile <andrew.den.exter@jollamobile.com>
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.LGPL included in the packaging
|
||||
** of this file.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Jellyfin {
|
||||
class QObjectSettingsWrapperPrivate;
|
||||
|
||||
/**
|
||||
* @brief Almost-API reimplementation of https://github.com/sailfishos/mlite/blob/master/src/mdconfgroup.h
|
||||
* that uses QSettings as a backend.
|
||||
*/
|
||||
class QObjectSettingsWrapper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(QObjectSettingsWrapper)
|
||||
Q_PROPERTY(bool synchronous READ isSynchronous WRITE setSynchronous NOTIFY synchronousChanged);
|
||||
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged);
|
||||
Q_PROPERTY(Jellyfin::QObjectSettingsWrapper *scope READ scope WRITE setScope NOTIFY scopeChanged);
|
||||
public:
|
||||
enum BindOption {
|
||||
DontBindProperties,
|
||||
BindProperties
|
||||
};
|
||||
|
||||
explicit QObjectSettingsWrapper(QObject *parent = nullptr, BindOption option = DontBindProperties);
|
||||
explicit QObjectSettingsWrapper(const QString &path, QObject *parent = nullptr, BindOption option = DontBindProperties);
|
||||
virtual ~QObjectSettingsWrapper();
|
||||
|
||||
bool isSynchronous() const;
|
||||
void setSynchronous(bool synchronous);
|
||||
|
||||
QString path() const;
|
||||
void setPath(const QString &path);
|
||||
|
||||
QObjectSettingsWrapper *scope() const;
|
||||
void setScope(QObjectSettingsWrapper *scope);
|
||||
|
||||
Q_INVOKABLE QVariant value(const QString &key,
|
||||
const QVariant &defaultValue = QVariant(),
|
||||
int typeHint = QMetaType::UnknownType) const;
|
||||
Q_INVOKABLE void setValue(const QString &key, const QVariant &value);
|
||||
signals:
|
||||
void synchronousChanged();
|
||||
void pathChanged();
|
||||
void scopeChanged();
|
||||
public slots:
|
||||
void sync();
|
||||
void clear();
|
||||
protected:
|
||||
void resolveMetaObject(int propertyOffset = -1);
|
||||
private slots:
|
||||
void propertyChanged();
|
||||
private:
|
||||
QScopedPointer<QObjectSettingsWrapperPrivate> d_ptr;
|
||||
};
|
||||
|
||||
} // NS Jellyfin
|
||||
#endif
|
||||
|
||||
#endif // JELLYFIN_QOBJECTSETTINGSWRAPPER_H
|
59
core/include/JellyfinQt/viewmodel/settings.h
Normal file
59
core/include/JellyfinQt/viewmodel/settings.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Sailfin: a Jellyfin client written using Qt
|
||||
* Copyright (C) 2021 Chris Josten and the Sailfin Contributors.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef JELLYFIN_VIEWMODEL_SETTINGS_H
|
||||
#define JELLYFIN_VIEWMODEL_SETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "JellyfinQt/qobjectsettingswrapper.h"
|
||||
|
||||
namespace Jellyfin {
|
||||
|
||||
class ApiClient;
|
||||
|
||||
namespace ViewModel {
|
||||
|
||||
|
||||
class Settings : public QObjectSettingsWrapper {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool allowTranscoding READ allowTranscoding WRITE setAllowTranscoding NOTIFY allowTranscodingChanged)
|
||||
Q_PROPERTY(int maxBitRate READ maxBitRate WRITE setMaxBitRate NOTIFY maxBitRateChanged)
|
||||
public:
|
||||
explicit Settings(ApiClient *apiClient);
|
||||
virtual ~Settings();
|
||||
|
||||
bool allowTranscoding() const;
|
||||
void setAllowTranscoding(bool allowTranscoding);
|
||||
|
||||
int maxBitRate() const;
|
||||
void setMaxBitRate(int newMaxBitRate);
|
||||
signals:
|
||||
void allowTranscodingChanged(bool newAllowTranscoding);
|
||||
void maxBitRateChanged(int newMaxBitRate);
|
||||
private:
|
||||
bool m_allowTranscoding = true;
|
||||
int m_maxBitRate = 5000000;
|
||||
};
|
||||
|
||||
|
||||
} // NS ViewModel
|
||||
} // NS Jellyfin
|
||||
|
||||
#endif // JELLYFIN_VIEWMODEL_SETTINGS_H
|
255
core/src/qobjectsettingswrapper.cpp
Normal file
255
core/src/qobjectsettingswrapper.cpp
Normal file
|
@ -0,0 +1,255 @@
|
|||
/*
|
||||
* Sailfin: a Jellyfin client written using Qt
|
||||
* Copyright (C) 2021 Chris Josten and the Sailfin Contributors
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/***************************************************************************
|
||||
** Copyright (C) 2014 Jolla Mobile <andrew.den.exter@jollamobile.com>
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.LGPL included in the packaging
|
||||
** of this file.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "JellyfinQt/qobjectsettingswrapper.h"
|
||||
|
||||
#ifndef USE_MLITE
|
||||
#include <QDebug>
|
||||
#include <QMetaProperty>
|
||||
#include <QMetaObject>
|
||||
#include <QSettings>
|
||||
|
||||
namespace Jellyfin {
|
||||
class QObjectSettingsWrapperPrivate {
|
||||
Q_DECLARE_PUBLIC(QObjectSettingsWrapper);
|
||||
public:
|
||||
explicit QObjectSettingsWrapperPrivate(QObjectSettingsWrapper *parent);
|
||||
virtual ~QObjectSettingsWrapperPrivate() {}
|
||||
void readValue(const QMetaProperty &prop);
|
||||
void resolveProperties(QByteArray path);
|
||||
|
||||
QSettings m_settings;
|
||||
int propertyOffset = -1;
|
||||
int notifyIndex = -1;
|
||||
QString path;
|
||||
QByteArray absolutePath;
|
||||
QObjectSettingsWrapper *scope = nullptr;
|
||||
QObjectSettingsWrapper *q_ptr = nullptr;
|
||||
QList<QObjectSettingsWrapper *> children;
|
||||
};
|
||||
|
||||
QObjectSettingsWrapper::QObjectSettingsWrapper(QObject *parent,
|
||||
BindOption bindOption)
|
||||
: QObject(parent),
|
||||
d_ptr(new QObjectSettingsWrapperPrivate(this)){
|
||||
|
||||
if (bindOption == DontBindProperties)
|
||||
resolveMetaObject(metaObject()->propertyCount());
|
||||
}
|
||||
|
||||
QObjectSettingsWrapper::QObjectSettingsWrapper(const QString &path,
|
||||
QObject *parent,
|
||||
BindOption bindOption)
|
||||
: QObject(parent),
|
||||
d_ptr(new QObjectSettingsWrapperPrivate(this)){
|
||||
|
||||
d_ptr->path = path;
|
||||
|
||||
if (bindOption == DontBindProperties)
|
||||
resolveMetaObject(metaObject()->propertyCount());
|
||||
}
|
||||
|
||||
QObjectSettingsWrapper::~QObjectSettingsWrapper() {}
|
||||
|
||||
bool QObjectSettingsWrapper::isSynchronous() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapper::setSynchronous(bool synchronous) {
|
||||
Q_UNUSED(synchronous)
|
||||
// NOOP
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapper::setPath(const QString &path) {
|
||||
Q_D(QObjectSettingsWrapper);
|
||||
if (d->path != path) {
|
||||
const bool isAbsolute = d->path.startsWith("/");
|
||||
d->path = path;
|
||||
emit pathChanged();
|
||||
|
||||
// If the new path is absolute connect to the changed signal and read the initial values,
|
||||
// if it's relative and the parent scope is valid just read the initial values.
|
||||
if (d->path.isEmpty() ||d->propertyOffset < 0) {
|
||||
// No path or the object is not yet resolved, so don't do any of the following things.
|
||||
} else if (isAbsolute) {
|
||||
d->resolveProperties(QByteArray());
|
||||
} else if (d->scope && !d->scope->d_func()->absolutePath.isEmpty()) {
|
||||
d->resolveProperties(d->scope->d_func()->absolutePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString QObjectSettingsWrapper::path() const {
|
||||
Q_D(const QObjectSettingsWrapper);
|
||||
return d_ptr->m_settings.group();
|
||||
}
|
||||
|
||||
QObjectSettingsWrapper *QObjectSettingsWrapper::scope() const {
|
||||
Q_D(const QObjectSettingsWrapper);
|
||||
return d->scope;
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapper::setScope(QObjectSettingsWrapper *scope) {
|
||||
Q_D(QObjectSettingsWrapper);
|
||||
const bool isAbsolute = d->path.startsWith("/");
|
||||
if (d->scope) {
|
||||
d->scope->d_func()->children.removeAll(this);
|
||||
}
|
||||
d->scope = scope;
|
||||
|
||||
if (d->scope) {
|
||||
d->scope->d_func()->children.append(this);
|
||||
|
||||
// If the path is relative and the new scope is valid read the initial values.
|
||||
if (!d->path.isEmpty() && !isAbsolute && !d->scope->d_func()->absolutePath.isEmpty()) {
|
||||
d->resolveProperties(d->scope->d_func()->absolutePath);
|
||||
}
|
||||
}
|
||||
|
||||
emit scopeChanged();
|
||||
}
|
||||
|
||||
QVariant QObjectSettingsWrapper::value(const QString &key, const QVariant &defaultValue, int typeHint) const {
|
||||
Q_UNUSED(typeHint)
|
||||
Q_D(const QObjectSettingsWrapper);
|
||||
const QByteArray absoluteKey = !key.startsWith(QLatin1Char('/'))
|
||||
? d->absolutePath + key.toUtf8()
|
||||
: key.toUtf8();
|
||||
QVariant value = d->m_settings.value(absoluteKey, defaultValue);
|
||||
return value.isValid() ? value : defaultValue;
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapper::setValue(const QString &key, const QVariant &value) {
|
||||
Q_D(QObjectSettingsWrapper);
|
||||
if (d->absolutePath.isEmpty() || key.isEmpty()) return;
|
||||
|
||||
const QByteArray absoluteKey = !key.startsWith(QLatin1Char('/'))
|
||||
? d->absolutePath + key.toUtf8()
|
||||
: key.toUtf8();
|
||||
d->m_settings.setValue(absoluteKey, value);
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapper::sync() {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapper::clear() {
|
||||
Q_D(QObjectSettingsWrapper);
|
||||
d->m_settings.clear();
|
||||
}
|
||||
|
||||
|
||||
void QObjectSettingsWrapper::resolveMetaObject(int propertyOffset) {
|
||||
Q_D(QObjectSettingsWrapper);
|
||||
qDebug() << "Resolving meta object";
|
||||
|
||||
if (d->propertyOffset >= 0) return;
|
||||
|
||||
const int propertyChangedIndex = staticMetaObject.indexOfMethod("propertyChanged()");
|
||||
Q_ASSERT(propertyChangedIndex != -1);
|
||||
|
||||
const QMetaObject * const metaObject = this->metaObject();
|
||||
|
||||
if (propertyOffset < 0) {
|
||||
propertyOffset = staticMetaObject.propertyCount();
|
||||
}
|
||||
d->propertyOffset = propertyOffset;
|
||||
qDebug() << "Property offset: " << propertyOffset << ", total properties: " << metaObject->propertyCount();
|
||||
|
||||
for (int i = propertyOffset; i < metaObject->propertyCount(); i++) {
|
||||
const QMetaProperty prop = metaObject->property(i);
|
||||
qDebug() << "Encountered prop " << prop.name();
|
||||
if (prop.hasNotifySignal()) {
|
||||
QMetaObject::connect(this,
|
||||
prop.notifySignalIndex(),
|
||||
this,
|
||||
propertyChangedIndex,
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
}
|
||||
|
||||
if (d->path.startsWith("/")) {
|
||||
d->resolveProperties("");
|
||||
} else if (d->scope && !d->path.isEmpty() && !d->scope->d_func()->absolutePath.isEmpty()) {
|
||||
d->resolveProperties(d->scope->d_func()->absolutePath);
|
||||
}
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapper::propertyChanged() {
|
||||
Q_D(QObjectSettingsWrapper);
|
||||
|
||||
const int notifyIndex = senderSignalIndex();
|
||||
if (notifyIndex == d->notifyIndex) return;
|
||||
|
||||
const QMetaObject * const metaObject = this->metaObject();
|
||||
|
||||
for (int i = d->propertyOffset; i < metaObject->propertyCount(); i++) {
|
||||
const QMetaProperty prop = metaObject->property(i);
|
||||
if (prop.notifySignalIndex() == notifyIndex) {
|
||||
qDebug() << "Property changed, name: " << prop.name();
|
||||
d->m_settings.setValue(d->absolutePath + prop.name(), prop.read(this));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
QObjectSettingsWrapperPrivate::QObjectSettingsWrapperPrivate(QObjectSettingsWrapper *parent)
|
||||
: q_ptr(parent),
|
||||
m_settings(QSettings(parent)) {
|
||||
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapperPrivate::resolveProperties(QByteArray scopePath) {
|
||||
absolutePath = scopePath + path.toUtf8() + '/';
|
||||
Q_Q(QObjectSettingsWrapper);
|
||||
|
||||
const QMetaObject * const metaObject = q->metaObject();
|
||||
for (int i = propertyOffset; i < metaObject->propertyCount(); i++) {
|
||||
readValue(metaObject->property(i));
|
||||
}
|
||||
}
|
||||
|
||||
void QObjectSettingsWrapperPrivate::readValue(const QMetaProperty &prop) {
|
||||
Q_Q(QObjectSettingsWrapper);
|
||||
const QVariant value = m_settings.value(absolutePath + prop.name(), prop.type());
|
||||
if (value.isValid()) {
|
||||
notifyIndex = prop.notifySignalIndex();
|
||||
prop.write(q, value);
|
||||
notifyIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
} // NS Jellyfin
|
||||
|
||||
#endif
|
||||
|
56
core/src/viewmodel/settings.cpp
Normal file
56
core/src/viewmodel/settings.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
Sailfin: a Jellyfin client written using Qt
|
||||
Copyright (C) 2021 Chris Josten
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "JellyfinQt/viewmodel/settings.h"
|
||||
|
||||
#include "JellyfinQt/apiclient.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace ViewModel {
|
||||
|
||||
Settings::Settings(ApiClient *apiClient)
|
||||
: QObjectSettingsWrapper(apiClient, BindProperties) {
|
||||
|
||||
this->setPath(QStringLiteral("/") + QCoreApplication::organizationDomain().replace(".", "/") + "/" + QCoreApplication::applicationName());
|
||||
resolveMetaObject();
|
||||
}
|
||||
|
||||
Settings::~Settings() {}
|
||||
|
||||
bool Settings::allowTranscoding() const {
|
||||
return m_allowTranscoding;
|
||||
}
|
||||
|
||||
void Settings::setAllowTranscoding(bool allowTranscoding) {
|
||||
m_allowTranscoding = allowTranscoding;
|
||||
emit allowTranscodingChanged(allowTranscoding);
|
||||
}
|
||||
|
||||
int Settings::maxBitRate() const {
|
||||
return m_maxBitRate;
|
||||
}
|
||||
|
||||
void Settings::setMaxBitRate(int newMaxBitRate) {
|
||||
m_maxBitRate = newMaxBitRate;
|
||||
emit maxBitRateChanged(newMaxBitRate);
|
||||
}
|
||||
|
||||
} // NS ViewModel
|
||||
} // NS Jellyfin
|
|
@ -24,6 +24,7 @@ PkgConfigBR:
|
|||
- Qt5Qml
|
||||
- Qt5Quick
|
||||
- Qt5WebSockets
|
||||
- mlite5
|
||||
|
||||
# Build dependencies without a pkgconfig setup can be listed here
|
||||
# PkgBR:
|
||||
|
@ -50,7 +51,7 @@ Macros:
|
|||
ConfigOptions:
|
||||
- -DPLATFORM_SAILFISHOS=1
|
||||
- -DSAILFIN_VERSION='%{version}-%{release}'
|
||||
|
||||
|
||||
# ExtraInstall: |
|
||||
# mv /home/deploy/installroot/home/deploy/installroot/usr/share/harbour-sailfin/plugins /home/deploy/installroot/usr/share/harbour-sailfin/plugins
|
||||
|
||||
|
|
Loading…
Reference in a new issue