File indexing completed on 2025-03-16 05:18:26

0001 /*
0002  * Copyright 2018 by Aditya Mehra <aix.m@outlook.com>
0003  *
0004  * Licensed under the Apache License, Version 2.0 (the "License");
0005  * you may not use this file except in compliance with the License.
0006  * You may obtain a copy of the License at
0007  *
0008  *    http://www.apache.org/licenses/LICENSE-2.0
0009  *
0010  * Unless required by applicable law or agreed to in writing, software
0011  * distributed under the License is distributed on an "AS IS" BASIS,
0012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013  * See the License for the specific language governing permissions and
0014  * limitations under the License.
0015  *
0016  */
0017 
0018 #ifndef GLOBALSETTINGS_H
0019 #define GLOBALSETTINGS_H
0020 
0021 #include <QSettings>
0022 #include <QCoreApplication>
0023 #include <QDebug>
0024 
0025 #define SettingPropertyKey(type, name, setOption, signalName, settingKey, defaultValue) \
0026     inline type name() const { return m_settings.value(settingKey, defaultValue).value<type>(); } \
0027     inline void setOption (const type &value) { m_settings.setValue(settingKey, value); emit signalName(); qDebug() << "emitted"; }
0028 
0029 class QSettings;
0030 class GlobalSettings : public QObject
0031 {
0032     Q_OBJECT
0033     Q_PROPERTY(QString webSocketAddress READ webSocketAddress WRITE setWebSocketAddress NOTIFY webSocketChanged)
0034     Q_PROPERTY(bool autoConnect READ autoConnect WRITE setAutoConnect NOTIFY autoConnectChanged)
0035     Q_PROPERTY(bool usesRemoteTTS READ usesRemoteTTS WRITE setUsesRemoteTTS NOTIFY usesRemoteTTSChanged)
0036     Q_PROPERTY(bool displayRemoteConfig READ displayRemoteConfig WRITE setDisplayRemoteConfig NOTIFY displayRemoteConfigChanged)
0037     Q_PROPERTY(bool usePTTClient READ usePTTClient WRITE setUsePTTClient NOTIFY usePTTClient)
0038     Q_PROPERTY(bool useHivemindProtocol READ useHivemindProtocol WRITE setUseHivemindProtocol NOTIFY useHivemindProtocolChanged)
0039     Q_PROPERTY(bool useEntryNameSpaceAnimation READ useEntryNameSpaceAnimation WRITE setUseEntryNameSpaceAnimation NOTIFY useEntryNameSpaceAnimationChanged)
0040     Q_PROPERTY(bool useExitNameSpaceAnimation READ useExitNameSpaceAnimation WRITE setUseExitNameSpaceAnimation NOTIFY useExitNameSpaceAnimationChanged)
0041     Q_PROPERTY(bool useFocusAnimation READ useFocusAnimation WRITE setUseFocusAnimation NOTIFY useFocusAnimationChanged)
0042     Q_PROPERTY(bool useDelegateAnimation READ useDelegateAnimation WRITE setUseDelegateAnimation NOTIFY useDelegateAnimationChanged)
0043 
0044 public:
0045     explicit GlobalSettings(QObject *parent=0);
0046 #ifndef Q_OS_ANDROID
0047     SettingPropertyKey(QString, webSocketAddress, setWebSocketAddress, webSocketChanged, QStringLiteral("webSocketAddress"), QStringLiteral("ws://0.0.0.0"))
0048 #else
0049     SettingPropertyKey(QString, webSocketAddress, setWebSocketAddress, webSocketChanged, QStringLiteral("webSocketAddress"), QStringLiteral("ws://104.248.21.254"))
0050 #endif
0051 
0052     bool autoConnect() const;
0053     void setAutoConnect(bool autoconnect);
0054     bool usesRemoteTTS() const;
0055     void setUsesRemoteTTS(bool usesRemoteTTS);
0056     bool displayRemoteConfig() const;
0057     void setDisplayRemoteConfig(bool displayRemoteConfig);
0058     bool usePTTClient() const;
0059     void setUsePTTClient(bool usePttClient);
0060     bool useHivemindProtocol() const;
0061     void setUseHivemindProtocol(bool useHivemindProtocol);
0062     bool useEntryNameSpaceAnimation() const;
0063     void setUseEntryNameSpaceAnimation(bool useEntryNameSpaceAnimation);
0064     bool useExitNameSpaceAnimation() const;
0065     void setUseExitNameSpaceAnimation(bool useExitNameSpaceAnimation);
0066     bool useFocusAnimation() const;
0067     void setUseFocusAnimation(bool useFocusAnimation);
0068     bool useDelegateAnimation() const;
0069     void setUseDelegateAnimation(bool useDelegateAnimation);
0070 
0071 Q_SIGNALS:
0072     void webSocketChanged();
0073     void autoConnectChanged();
0074     void usesRemoteTTSChanged();
0075     void displayRemoteConfigChanged();
0076     void usePTTClientChanged();
0077     void useHivemindProtocolChanged();
0078     void useEntryNameSpaceAnimationChanged();
0079     void useExitNameSpaceAnimationChanged();
0080     void useFocusAnimationChanged();
0081     void useDelegateAnimationChanged();
0082 
0083 private:
0084     QSettings m_settings;
0085 };
0086 
0087 #endif // GLOBALSETTINGS_H