feat(settings): add data-layer mocks

main
reionwong 1 month ago
parent 128dc564ca
commit 82cb250b07

@ -66,6 +66,7 @@ set(SRCS
src/networkproxy.cpp
src/defaultapplications.cpp
src/inputmethod.cpp
src/mock/networkmockmodel.cpp
)
set(RESOURCES

@ -21,6 +21,7 @@
#include "notifications.h"
#include "password.h"
#include "powermanager.h"
#include "mock/networkmockmodel.h"
#include "settingsuiadaptor.h"
#include "touchpad.h"
#include "thumbnailprovider.h"
@ -52,6 +53,8 @@ Application::Application(int &argc, char **argv)
QCommandLineOption moduleOption("m", "Switch to module", "module");
parser.addOption(moduleOption);
parser.addOption(QCommandLineOption("mock-network", "Show sample network data"));
parser.addOption(QCommandLineOption("mock-battery", "Show sample battery data"));
parser.process(*this);
const QString module = parser.value(moduleOption);
@ -90,6 +93,7 @@ Application::Application(int &argc, char **argv)
qmlRegisterType<NetworkProxy>(uri, 1, 0, "NetworkProxy");
qmlRegisterType<Notifications>(uri, 1, 0, "Notifications");
qmlRegisterType<DefaultApplications>(uri, 1, 0, "DefaultApplications");
qmlRegisterType<NetworkMockModel>(uri, 1, 0, "NetworkMockModel");
qmlRegisterSingletonType<Password>(uri, 1, 0, "Password", passwordSingleton);

@ -18,6 +18,7 @@
*/
#include "battery.h"
#include <QCoreApplication>
#include <QDBusArgument>
#include <QDBusReply>
#include <QDateTime>
@ -28,6 +29,11 @@ static const QString s_sServer = "com.cutefish.Services";
static const QString s_sPath = "/com/cutefish/Services/Battery";
static const QString s_sInterface = "com.cutefish.Services.Battery";
static bool mockBatteryEnabled()
{
return QCoreApplication::arguments().contains(QStringLiteral("--mock-battery"));
}
// DBus Battery Info Structure
struct BatteryInfo {
uint time, state;
@ -60,6 +66,13 @@ Battery::Battery(QObject *parent)
, m_available(false)
, m_onBattery(false)
{
if (mockBatteryEnabled()) {
m_available = true;
m_onBattery = true;
m_udi = QStringLiteral("mock-battery");
return;
}
m_available = m_interface.isValid() && !m_interface.lastError().isValid();
if (m_available) {
@ -109,6 +122,9 @@ bool Battery::onBattery() const
void Battery::refresh()
{
if (mockBatteryEnabled())
return;
m_interface.call("refresh");
}
@ -147,42 +163,66 @@ QVariantList Battery::getHistory(const int timespan, const int resolution)
int Battery::chargeState() const
{
if (mockBatteryEnabled())
return 2;
return m_interface.property("chargeState").toInt();
}
int Battery::chargePercent() const
{
if (mockBatteryEnabled())
return 78;
return m_interface.property("chargePercent").toInt();
}
int Battery::lastChargedPercent() const
{
if (mockBatteryEnabled())
return 100;
return m_interface.property("lastChargedPercent").toInt();
}
int Battery::capacity() const
{
if (mockBatteryEnabled())
return 94;
return m_interface.property("capacity").toInt();
}
QString Battery::statusString() const
{
if (mockBatteryEnabled())
return tr("Discharging · 3 hours 24 minutes remaining");
return m_interface.property("statusString").toString();
}
QString Battery::lastChargedTime() const
{
if (mockBatteryEnabled())
return tr("2 hours ago");
return m_interface.property("lastChargedTime").toString();
}
bool Battery::showPercent()
{
if (mockBatteryEnabled())
return true;
QSettings settings(QSettings::UserScope, "cutefish", "statusbar");
return settings.value("BatteryPercentage", false).toBool();
}
void Battery::setPercentEnabled(bool value)
{
if (mockBatteryEnabled())
return;
QDBusInterface("com.cutefish.Statusbar", "/Statusbar").call("setBatteryPercentage", value);
}

@ -20,6 +20,8 @@
#include "batteryhistorymodel.h"
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QDBusArgument>
#include <QDBusConnection>
@ -165,6 +167,26 @@ void BatteryHistoryModel::load()
return;
}
if (QCoreApplication::arguments().contains(QStringLiteral("--mock-battery"))) {
m_values.clear();
const uint now = QDateTime::currentSecsSinceEpoch();
const QList<double> chargeValues { 96, 92, 88, 83, 77, 71, 64, 59, 65, 70, 74, 78 };
const QList<double> rateValues { 8.2, 7.6, 7.1, 6.8, 6.4, 5.9, 6.3, 7.0, 6.5, 6.1, 5.8, 5.5 };
const auto &values = m_type == RateType ? rateValues : chargeValues;
const uint interval = m_duration / values.size();
for (int i = 0; i < values.size(); ++i) {
HistoryReply reply;
reply.time = now - m_duration + interval * i;
reply.value = values.at(i);
reply.charging = 0;
m_values.append(reply);
}
Q_EMIT dataChanged();
return;
}
auto msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.UPower"),
m_device,
QStringLiteral("org.freedesktop.UPower.Device"),

@ -0,0 +1,157 @@
#include "networkmockmodel.h"
#include <QDateTime>
namespace {
constexpr int activated = 2;
constexpr int deactivated = 4;
constexpr int availableConnection = 1;
constexpr int availableAccessPoint = 2;
constexpr int wiredType = 13;
constexpr int wirelessType = 14;
constexpr int noSecurity = 0;
constexpr int wpa2Psk = 7;
constexpr int sae = 9;
}
NetworkMockModel::NetworkMockModel(QObject *parent)
: QAbstractListModel(parent)
{
const QDateTime now = QDateTime::currentDateTime();
m_items = {
{
{ "name", QStringLiteral("Cutefish Studio") },
{ "connectionIcon", QStringLiteral("network-wireless-connected-100") },
{ "connectionState", activated },
{ "itemType", availableConnection },
{ "securityType", wpa2Psk },
{ "securityTypeString", QStringLiteral("WPA2 Personal") },
{ "signal", 92 },
{ "type", wirelessType },
{ "uuid", QStringLiteral("mock-wifi-connected") },
{ "ipAddress", QStringLiteral("192.168.1.86") },
{ "router", QStringLiteral("192.168.1.1") },
{ "gateWay", QStringLiteral("192.168.1.1") },
{ "timeStamp", now }
},
{
{ "name", QStringLiteral("Coffee Shop") },
{ "connectionIcon", QStringLiteral("network-wireless-connected-75") },
{ "connectionState", deactivated },
{ "itemType", availableAccessPoint },
{ "securityType", wpa2Psk },
{ "securityTypeString", QStringLiteral("WPA2 Personal") },
{ "signal", 74 },
{ "type", wirelessType },
{ "uuid", QStringLiteral("mock-wifi-saved") },
{ "timeStamp", now.addSecs(-3600) }
},
{
{ "name", QStringLiteral("Guest Network") },
{ "connectionIcon", QStringLiteral("network-wireless-connected-50") },
{ "connectionState", deactivated },
{ "itemType", availableAccessPoint },
{ "securityType", noSecurity },
{ "securityTypeString", QStringLiteral("None") },
{ "signal", 51 },
{ "type", wirelessType },
{ "timeStamp", now.addSecs(-7200) }
},
{
{ "name", QStringLiteral("Neighbor Wi-Fi") },
{ "connectionIcon", QStringLiteral("network-wireless-connected-25") },
{ "connectionState", deactivated },
{ "itemType", availableAccessPoint },
{ "securityType", sae },
{ "securityTypeString", QStringLiteral("WPA3 Personal") },
{ "signal", 28 },
{ "type", wirelessType },
{ "timeStamp", now.addSecs(-10800) }
},
{
{ "name", QStringLiteral("Wired connection 1") },
{ "connectionIcon", QStringLiteral("network-wired") },
{ "connectionState", activated },
{ "itemType", availableConnection },
{ "securityType", noSecurity },
{ "signal", 100 },
{ "type", wiredType },
{ "uuid", QStringLiteral("mock-wired-connected") },
{ "timeStamp", now }
},
{
{ "name", QStringLiteral("USB Ethernet") },
{ "connectionIcon", QStringLiteral("network-wired") },
{ "connectionState", deactivated },
{ "itemType", availableConnection },
{ "securityType", noSecurity },
{ "signal", 100 },
{ "type", wiredType },
{ "uuid", QStringLiteral("mock-wired-usb") },
{ "timeStamp", now.addSecs(-18000) }
}
};
for (int i = 0; i < m_items.size(); ++i) {
auto &item = m_items[i];
const QString name = item.value("name").toString();
item["itemUniqueName"] = name;
item["ssid"] = name;
item["connectionPath"] = QString();
item["devicePath"] = QStringLiteral("/mock/device/%1").arg(i);
item["specificPath"] = QStringLiteral("/mock/network/%1").arg(i);
item["slave"] = false;
}
}
int NetworkMockModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_items.size();
}
QVariant NetworkMockModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_items.size())
return {};
const QByteArray roleName = roleNames().value(role);
return m_items.at(index.row()).value(QString::fromLatin1(roleName));
}
QHash<int, QByteArray> NetworkMockModel::roleNames() const
{
return {
{ ConnectionDetailsRole, "connectionDetails" },
{ ConnectionIconRole, "connectionIcon" },
{ ConnectionPathRole, "connectionPath" },
{ ConnectionStateRole, "connectionState" },
{ DeviceNameRole, "deviceName" },
{ DevicePathRole, "devicePath" },
{ DeviceStateRole, "deviceState" },
{ DuplicateRole, "duplicate" },
{ ItemUniqueNameRole, "itemUniqueName" },
{ ItemTypeRole, "itemType" },
{ LastUsedRole, "lastUsed" },
{ LastUsedDateOnlyRole, "lastUsedDateOnly" },
{ NameRole, "name" },
{ SecurityTypeRole, "securityType" },
{ SecurityTypeStringRole, "securityTypeString" },
{ SectionRole, "section" },
{ SignalRole, "signal" },
{ SlaveRole, "slave" },
{ SsidRole, "ssid" },
{ SpecificPathRole, "specificPath" },
{ TimeStampRole, "timeStamp" },
{ TypeRole, "type" },
{ UniRole, "uni" },
{ UuidRole, "uuid" },
{ VpnStateRole, "vpnState" },
{ VpnTypeRole, "vpnType" },
{ RxBytesRole, "rxBytes" },
{ TxBytesRole, "txBytes" },
{ IpAddressRole, "ipAddress" },
{ RouterRole, "router" },
{ GateWayRole, "gateWay" }
};
}

@ -0,0 +1,53 @@
#pragma once
#include <QAbstractListModel>
#include <QVariantMap>
class NetworkMockModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit NetworkMockModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
private:
enum Role {
ConnectionDetailsRole = Qt::UserRole + 1,
ConnectionIconRole,
ConnectionPathRole,
ConnectionStateRole,
DeviceNameRole,
DevicePathRole,
DeviceStateRole,
DuplicateRole,
ItemUniqueNameRole,
ItemTypeRole,
LastUsedRole,
LastUsedDateOnlyRole,
NameRole,
SecurityTypeRole,
SecurityTypeStringRole,
SectionRole,
SignalRole,
SlaveRole,
SsidRole,
SpecificPathRole,
TimeStampRole,
TypeRole,
UniRole,
UuidRole,
VpnStateRole,
VpnTypeRole,
RxBytesRole,
TxBytesRole,
IpAddressRole,
RouterRole,
GateWayRole
};
QList<QVariantMap> m_items;
};

@ -39,7 +39,7 @@ Canvas {
property int xPadding: 45
property int yPadding: 40
property var data //expect an array of QPointF
property var data: [] //expect an array of QPointF
property real yMax: 100
property real xMax: 100
@ -55,6 +55,13 @@ Canvas {
property real xDivisionWidth: 600000
property real xTicksAt: xTicksAtDontCare
readonly property real xTicksAtDontCare: 0
readonly property real xTicksAtTwelveOClock: 1
readonly property real xTicksAtFullHour: 2
readonly property real xTicksAtHalfHour: 3
readonly property real xTicksAtFullSecondHour: 4
readonly property real xTicksAtTenMinutes: 5
//internal
property real plotWidth: width - xPadding * 1.5
@ -87,6 +94,9 @@ Canvas {
c.clearRect(0,0, width, height)
if (!data || data.length < 2)
return
//draw the background
c.fillStyle = bgColor
c.fillRect(xPadding, yPadding, plotWidth, plotHeight);

@ -153,12 +153,6 @@ ItemPage {
data: history.points
readonly property real xTicksAtDontCare: 0
readonly property real xTicksAtTwelveOClock: 1
readonly property real xTicksAtFullHour: 2
readonly property real xTicksAtHalfHour: 3
readonly property real xTicksAtFullSecondHour: 4
readonly property real xTicksAtTenMinutes: 5
readonly property var xTicksAtList: [xTicksAtTenMinutes, xTicksAtHalfHour, xTicksAtHalfHour,
xTicksAtFullHour, xTicksAtFullSecondHour, xTicksAtTwelveOClock]

@ -467,7 +467,7 @@ Item {
id: nmEnabledConnections
Component.onCompleted: {
if (!nmEnabledConnections.wirelessHwEnabled)
if (!nmEnabledConnections.wirelessHwEnabled && !rootWindow.mockNetworkData)
removeItem("wlan")
}
}

@ -22,6 +22,7 @@ import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import FishUI 1.0 as FishUI
import Cutefish.Settings 1.0
import Cutefish.Network 1.0 as NM
import "../"
@ -45,6 +46,10 @@ ItemPage {
id: networkModel
}
NetworkMockModel {
id: mockNetworkModel
}
NM.EnabledConnections {
id: enabledConnections
}
@ -66,21 +71,22 @@ ItemPage {
}
Component.onCompleted: {
handler.requestScan()
if (!rootWindow.mockNetworkData)
handler.requestScan()
}
Timer {
id: scanTimer
interval: 10200
repeat: true
running: control.visible
running: control.visible && !rootWindow.mockNetworkData
onTriggered: handler.requestScan()
}
Scrollable {
anchors.fill: parent
contentHeight: mainLayout.implicitHeight
visible: enabledConnections.wirelessHwEnabled
visible: enabledConnections.wirelessHwEnabled || rootWindow.mockNetworkData
ColumnLayout {
id: mainLayout
@ -90,7 +96,8 @@ ItemPage {
RoundedItem {
WifiView {
Layout.fillWidth: true
visible: enabledConnections.wirelessHwEnabled
visible: enabledConnections.wirelessHwEnabled || rootWindow.mockNetworkData
sourceModel: rootWindow.mockNetworkData ? mockNetworkModel : connectionModel
}
}

@ -28,6 +28,7 @@ import Cutefish.Network 1.0 as NM
ColumnLayout {
id: _contentLayout
spacing: FishUI.Units.largeSpacing
property var sourceModel: connectionModel
ConnectDialog {
id: connectDialog
@ -64,8 +65,11 @@ ColumnLayout {
rightPadding: 0
rightInset: 0
checked: enabledConnections.wirelessEnabled
checked: rootWindow.mockNetworkData || enabledConnections.wirelessEnabled
onCheckedChanged: {
if (rootWindow.mockNetworkData)
return
if (checked) {
if (!enabledConnections.wirelessEnabled) {
handler.enableWireless(checked)
@ -99,7 +103,7 @@ ColumnLayout {
model: NM.AppletProxyModel {
type: NM.AppletProxyModel.WirelessType
sourceModel: connectionModel
sourceModel: _contentLayout.sourceModel
}
spacing: 0

@ -137,7 +137,7 @@ FishUI.Window {
Label {
id: ipv4AddressLabel
// text: model.ipV4Address
text: model.ipAddress
Layout.alignment: Qt.AlignRight
Layout.fillWidth: true
}
@ -176,7 +176,7 @@ FishUI.Window {
Label {
id: routerLabel
// text: model.gateway
text: model.gateWay
Layout.alignment: Qt.AlignRight
}

@ -22,6 +22,7 @@ import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import FishUI 1.0 as FishUI
import Cutefish.Settings 1.0
import Cutefish.Network 1.0 as NM
import "../"
@ -45,6 +46,10 @@ ItemPage {
id: networkModel
}
NetworkMockModel {
id: mockNetworkModel
}
NM.EnabledConnections {
id: enabledConnections
}
@ -89,7 +94,7 @@ ItemPage {
model: NM.AppletProxyModel {
type: NM.AppletProxyModel.WiredType
sourceModel: connectionModel
sourceModel: rootWindow.mockNetworkData ? mockNetworkModel : connectionModel
}
ScrollBar.vertical: ScrollBar {}

@ -35,6 +35,7 @@ FishUI.Window {
property alias stackView: _stackView
property string pendingPageName: ""
readonly property bool mockNetworkData: Qt.application.arguments.indexOf("--mock-network") >= 0
// Entries are {page, rootPage, properties}; rootPage is the sidebar page a sub page belongs to.
property var history: []

Loading…
Cancel
Save