mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: create qPrefFacebook from SettingsObjectWrapper
Update set/get functions to follow common name scheme: - get function have same name as in struct diveComputer - set function have set_<name> - signal function have <name>_changed one class one .h/.cpp is the C++ idiom. Having load/sync of each variable in 1 functions (in contrast to the distributed way SettingsObjectWrapper handles it) secures the same storage name is used. Having the set/get/load/sync functions grouped together makes it easier to get an overview. REMARK: this commit only defines the class, it is not active in production Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
parent
75661186d3
commit
e0f1817fdc
6 changed files with 93 additions and 0 deletions
|
@ -104,6 +104,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
||||||
settings/qPrefCloudStorage.cpp
|
settings/qPrefCloudStorage.cpp
|
||||||
settings/qPrefDisplay.cpp
|
settings/qPrefDisplay.cpp
|
||||||
settings/qPrefDiveComputer.cpp
|
settings/qPrefDiveComputer.cpp
|
||||||
|
settings/qPrefFacebook.cpp
|
||||||
settings/qPrefPrivate.cpp
|
settings/qPrefPrivate.cpp
|
||||||
|
|
||||||
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
|
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "qPrefCloudStorage.h"
|
#include "qPrefCloudStorage.h"
|
||||||
#include "qPrefDisplay.h"
|
#include "qPrefDisplay.h"
|
||||||
#include "qPrefDiveComputer.h"
|
#include "qPrefDiveComputer.h"
|
||||||
|
#include "qPrefFacebook.h"
|
||||||
|
|
||||||
class qPref : public QObject {
|
class qPref : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
43
core/settings/qPrefFacebook.cpp
Normal file
43
core/settings/qPrefFacebook.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#include "qPref.h"
|
||||||
|
#include "qPrefPrivate.h"
|
||||||
|
|
||||||
|
static const QString group = QStringLiteral("WebApps/Facebook");
|
||||||
|
|
||||||
|
qPrefFacebook::qPrefFacebook(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
qPrefFacebook*qPrefFacebook::instance()
|
||||||
|
{
|
||||||
|
static qPrefFacebook *self = new qPrefFacebook;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void qPrefFacebook::loadSync(bool doSync)
|
||||||
|
{
|
||||||
|
// Empty, because FB probs are not loaded/synced to disk
|
||||||
|
}
|
||||||
|
|
||||||
|
void qPrefFacebook::set_access_token(const QString &value)
|
||||||
|
{
|
||||||
|
if (value != prefs.facebook.access_token) {
|
||||||
|
qPrefPrivate::instance()->copy_txt(&prefs.facebook.access_token, value);
|
||||||
|
emit access_token_changed(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void qPrefFacebook::set_album_id(const QString &value)
|
||||||
|
{
|
||||||
|
if (value != prefs.facebook.album_id) {
|
||||||
|
qPrefPrivate::instance()->copy_txt(&prefs.facebook.album_id, value);
|
||||||
|
emit album_id_changed(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void qPrefFacebook::set_user_id(const QString &value)
|
||||||
|
{
|
||||||
|
if (value != prefs.facebook.user_id) {
|
||||||
|
qPrefPrivate::instance()->copy_txt(&prefs.facebook.user_id, value);
|
||||||
|
emit access_token_changed(value);
|
||||||
|
}
|
||||||
|
}
|
45
core/settings/qPrefFacebook.h
Normal file
45
core/settings/qPrefFacebook.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#ifndef QPREFSFACEBOOK_H
|
||||||
|
#define QPREFSFACEBOOK_H
|
||||||
|
#include "core/pref.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
class qPrefFacebook : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString access_token READ access_token WRITE set_access_token NOTIFY access_token_changed);
|
||||||
|
Q_PROPERTY(QString album_id READ album_id WRITE set_album_id NOTIFY album_id_changed);
|
||||||
|
Q_PROPERTY(QString user_id READ user_id WRITE set_user_id NOTIFY user_id_changed);
|
||||||
|
|
||||||
|
public:
|
||||||
|
qPrefFacebook(QObject *parent = NULL);
|
||||||
|
static qPrefFacebook *instance();
|
||||||
|
|
||||||
|
// Load/Sync local settings (disk) and struct preference
|
||||||
|
void loadSync(bool doSync);
|
||||||
|
void inline load() {loadSync(false); }
|
||||||
|
void inline sync() {loadSync(true); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
static inline QString access_token() { return prefs.facebook.access_token; }
|
||||||
|
static inline QString album_id() { return prefs.facebook.album_id; }
|
||||||
|
static inline QString user_id() { return prefs.facebook.user_id; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void set_access_token(const QString& value);
|
||||||
|
void set_album_id(const QString& value);
|
||||||
|
void set_user_id(const QString& value);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void access_token_changed(const QString& value);
|
||||||
|
void album_id_changed(const QString& value);
|
||||||
|
void user_id_changed(const QString& value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void disk_access_token(bool doSync);
|
||||||
|
void disk_album_id(bool doSync);
|
||||||
|
void disk_user_id(bool doSync);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -18,6 +18,7 @@ public:
|
||||||
friend class qPrefCloudStorage;
|
friend class qPrefCloudStorage;
|
||||||
friend class qPrefDisplay;
|
friend class qPrefDisplay;
|
||||||
friend class qPrefDiveComputer;
|
friend class qPrefDiveComputer;
|
||||||
|
friend class qPrefFacebook;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static qPrefPrivate *instance();
|
static qPrefPrivate *instance();
|
||||||
|
|
|
@ -82,6 +82,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \
|
||||||
../../core/settings/qPrefCloudStorage.cpp \
|
../../core/settings/qPrefCloudStorage.cpp \
|
||||||
../../core/settings/qPrefDisplay.cpp \
|
../../core/settings/qPrefDisplay.cpp \
|
||||||
../../core/settings/qPrefDiveComputer.cpp \
|
../../core/settings/qPrefDiveComputer.cpp \
|
||||||
|
../../core/settings/qPrefFacebook.cpp \
|
||||||
../../core/settings/qPrefPrivate.cpp \
|
../../core/settings/qPrefPrivate.cpp \
|
||||||
../../core/subsurface-qt/CylinderObjectHelper.cpp \
|
../../core/subsurface-qt/CylinderObjectHelper.cpp \
|
||||||
../../core/subsurface-qt/DiveObjectHelper.cpp \
|
../../core/subsurface-qt/DiveObjectHelper.cpp \
|
||||||
|
@ -194,6 +195,7 @@ HEADERS += \
|
||||||
../../core/settings/qPrefCloudStorage.h \
|
../../core/settings/qPrefCloudStorage.h \
|
||||||
../../core/settings/qPrefDisplay.h \
|
../../core/settings/qPrefDisplay.h \
|
||||||
../../core/settings/qPrefDiveComputer.h \
|
../../core/settings/qPrefDiveComputer.h \
|
||||||
|
../../core/settings/qPrefFacebook.h \
|
||||||
../../core/settings/qPrefPrivate.h \
|
../../core/settings/qPrefPrivate.h \
|
||||||
../../core/subsurface-qt/CylinderObjectHelper.h \
|
../../core/subsurface-qt/CylinderObjectHelper.h \
|
||||||
../../core/subsurface-qt/DiveObjectHelper.h \
|
../../core/subsurface-qt/DiveObjectHelper.h \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue