Skip to content

Commit

Permalink
Custom devices
Browse files Browse the repository at this point in the history
  • Loading branch information
R1tschY committed Aug 18, 2020
1 parent c03c3b1 commit 0288383
Show file tree
Hide file tree
Showing 22 changed files with 447 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/qml/components/MprisUi.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import QtQuick 2.0
import Sailfish.Silica 1.0
import SailfishConnect.UI 0.3
import SailfishConnect.UI 0.6
import SailfishConnect.Api 0.6

Column {
Expand Down
2 changes: 1 addition & 1 deletion app/qml/cover/CoverPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import QtQuick 2.0
import Sailfish.Silica 1.0
import SailfishConnect.UI 0.3
import SailfishConnect.UI 0.6

CoverBackground {
id: cover
Expand Down
53 changes: 53 additions & 0 deletions app/qml/pages/AddCustomDeviceDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2020 Richard Liebscher <[email protected]>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.6
import Sailfish.Silica 1.0
import SailfishConnect.Qml 0.6
import "../components"

Dialog {
id: page

property string key: ""
property alias address: addressField.text

allowedOrientations: Orientation.All

canAccept: !!address

SilicaFlickable {
anchors.fill: parent
contentHeight: mainColumn.height

Column {
id: mainColumn
width: parent.width

DialogHeader { }

TextField {
id: addressField
width: parent.width
placeholderText: i18n("IPv4 or IPv6 address of device")
label: i18n("IP address")
validator: HostAddressValidator { }
focus: true
}
}
}
}
5 changes: 3 additions & 2 deletions app/qml/pages/DeviceListPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import Nemo.Notifications 1.0
import SailfishConnect.UI 0.3
import SailfishConnect.UI 0.6
import SailfishConnect.Api 0.6

Page {
Expand Down Expand Up @@ -300,7 +300,8 @@ Page {
pageStack.pop(page, PageStackAction.Immediate)
pageStack.push(
Qt.resolvedUrl("DevicePage.qml"),
{ deviceId: deviceId })
{ deviceId: deviceId },
PageStackAction.Immediate)
}
}

8 changes: 0 additions & 8 deletions app/qml/pages/DevicePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ Page {
anchors.fill: parent
contentHeight: deviceColumn.height + Theme.paddingLarge

onStateChanged: {
console.log(state)
}

Component.onCompleted: {
console.log(state)
}

states: [
State {
name: "notReachable"
Expand Down
2 changes: 1 addition & 1 deletion app/qml/pages/DevicePluginsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import QtQuick 2.0
import Sailfish.Silica 1.0
import SailfishConnect.UI 0.3
import SailfishConnect.UI 0.6
import SailfishConnect.Api 0.6

Page {
Expand Down
88 changes: 86 additions & 2 deletions app/qml/pages/SettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import SailfishConnect.Api 0.6

import SailfishConnect.UI 0.6

Page {
id: page
Expand All @@ -34,7 +34,6 @@ Page {
id: content

width: page.width
spacing: Theme.paddingLarge

PageHeader {
title: i18n("Settings")
Expand All @@ -50,6 +49,91 @@ Page {
onClicked: ui.runInBackground = !checked
automaticCheck: false
}

SectionHeader {
text: i18n("Custom devices")
}
ColumnView {
id: customDevicesView
model: SortFilterModel {
id: sortedCustomDevicesModel
sortRole: "stringData"
filterMode: "none"
sourceModel: StringListModel {
id: customDevicesModel
onStringListChanged: daemon.customDevices = stringList
Component.onCompleted: stringList = daemon.customDevices
}
}

itemHeight: Theme.itemSizeExtraSmall

delegate: ListItem {
id: listItem
contentHeight: Theme.itemSizeExtraSmall

menu: ContextMenu {
MenuItem {
text: i18n("Edit")
onClicked: {
var dialog = pageStack.push(
Qt.resolvedUrl("AddCustomDeviceDialog.qml"),
{ "key": display, "address": display })
dialog.accepted.connect(function() {
display = dialog.address
})
}
}

MenuItem {
text: i18n("Remove")
onClicked: customDevicesModel.removeOne(display)
}
}

Label {
x: Theme.horizontalPageMargin
y: Theme.paddingMedium
width: page.width - 2 * Theme.horizontalPageMargin
height: Theme.itemSizeExtraSmall
text: display
font.pixelSize: Theme.fontSizeMedium
}
}
}

Label {
id: replacement

x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
height: Theme.itemSizeExtraSmall

visible: customDevicesView.count === 0
opacity: visible ? 1.0 : 0

text: i18n("No custom devices")
horizontalAlignment: Text.AlignHCenter
font {
pixelSize: Theme.fontSizeMedium
family: Theme.fontFamilyHeading
}
color: Theme.rgba(Theme.highlightColor, 0.6)

Behavior on opacity { FadeAnimation { duration: 300 } }
}
}

PullDownMenu {
MenuItem {
text: i18n("Add custom device")
onClicked: {
var dialog = pageStack.push(Qt.resolvedUrl("AddCustomDeviceDialog.qml"))
dialog.accepted.connect(function() {
customDevicesModel.append(dialog.address)
})
}
}
}

VerticalScrollDecorator { flickable: pageFlickable }
Expand Down
2 changes: 1 addition & 1 deletion app/qml/pages/pluginConfigs/RunCommandsConfigPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Page {
onClicked: {
var dialog = pageStack.push(
Qt.resolvedUrl("AddCommandDialog.qml"),
{"key": key, "name": name, "command": command})
{ "key": key, "name": name, "command": command })
dialog.accepted.connect(function() {
commandsModel.editCommand(
dialog.key, dialog.name.trim(), dialog.command.trim())
Expand Down
1 change: 0 additions & 1 deletion app/src/dbus/kdeconnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <dbusinterfaces.h>
#include <core/kdeconnectpluginconfig.h>
#include <QJSValue>

class KdeConnectPluginConfig;

Expand Down
41 changes: 41 additions & 0 deletions app/src/js/hostaddressvalidator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2020 Richard Liebscher <[email protected]>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "hostaddressvalidator.h"

#include <QQmlEngine>
#include <QtQml>

namespace QmlJs {

HostAddressValidator::HostAddressValidator(QObject* parent)
: QValidator(parent)
{
}

void HostAddressValidator::registerType()
{
qmlRegisterType<HostAddressValidator>("SailfishConnect.Qml", 0, 6, "HostAddressValidator");
}

QValidator::State HostAddressValidator::validate(QString& input, int& pos) const
{
QHostAddress address(input);
return address.isNull() ? QValidator::Intermediate : QValidator::Acceptable;
}

} // namespace QmlJs
35 changes: 35 additions & 0 deletions app/src/js/hostaddressvalidator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Richard Liebscher <[email protected]>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QValidator>

namespace QmlJs {

class HostAddressValidator : public QValidator
{
Q_OBJECT
public:
explicit HostAddressValidator(QObject *parent = nullptr);

static void registerType();

State validate(QString &input, int &pos) const override;
};

} // namespace QmlJs
2 changes: 2 additions & 0 deletions app/src/js/qmlregister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "humanize.h"
#include "process.h"
#include "path.h"
#include "hostaddressvalidator.h"

namespace QmlJs {

Expand All @@ -30,6 +31,7 @@ void registerTypes()
Humanize::registerType();
Process::registerType();
Path::registerType();
HostAddressValidator::registerType();
}

} // namespace QmlJs
5 changes: 1 addition & 4 deletions app/src/models/devicelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ int DeviceListModel::rowCount(const QModelIndex &parent) const

QVariant DeviceListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();

if (index.row() >= m_devices.length())
if (index.row() < 0 || index.row() >= m_devices.length())
return QVariant();

auto& device = m_devices[index.row()];
Expand Down
2 changes: 1 addition & 1 deletion app/src/models/devicelistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DeviceListModel : public QAbstractListModel
WaitsForPairingRole
};

explicit DeviceListModel(QObject *parent = 0);
explicit DeviceListModel(QObject *parent = nullptr);
~DeviceListModel();

// Basic functionality:
Expand Down
2 changes: 1 addition & 1 deletion app/src/models/devicepluginsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int DevicePluginsModel::rowCount(const QModelIndex& parent) const

QVariant DevicePluginsModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || index.row() >= m_plugins.length())
if (index.row() < 0 || index.row() >= m_plugins.length())
return QVariant();

auto& metadata = m_plugins[index.row()];
Expand Down
2 changes: 1 addition & 1 deletion app/src/models/devicepluginsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DevicePluginsModel : public QAbstractListModel
IdRole,
};

explicit DevicePluginsModel(QObject *parent = 0);
explicit DevicePluginsModel(QObject *parent = nullptr);

int rowCount(const QModelIndex &parent = QModelIndex()) const override;

Expand Down
2 changes: 1 addition & 1 deletion app/src/models/mprisplayersmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int MprisPlayersModel::rowCount(const QModelIndex &parent) const

QVariant MprisPlayersModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= m_players.size())
if (index.row() < 0 || index.row() >= m_players.size())
return QVariant();

auto player = m_plugin->player(m_players[index.row()]);
Expand Down
Loading

0 comments on commit 0288383

Please sign in to comment.