Skip to content

Commit

Permalink
Implemented Open remote file from network and auto reload from network
Browse files Browse the repository at this point in the history
- Supports HTTP, HTTPS, and FTP protocols.
- A button to adjust reload times indicates, in local time, when the next reload will trigger.
- Time to reload can be specified in hours, minutes and seconds.

Fixes #143, adds the foundations for #141.
  • Loading branch information
Cuperino committed Feb 25, 2023
1 parent c81002d commit e4301be
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/icons/16/document-open-remote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<file alias="document-save-as.svg">16/document-save-as.svg</file>
<file alias="document-open.svg">16/document-open.svg</file>
<file alias="document-open-recent.svg">16/document-open-recent.svg</file>
<file alias="document-open-remote.svg">16/document-open-remote.svg</file>
<file alias="format-font-size-more.svg">16/format-font-size-more.svg</file>
<file alias="edit-clear-history.svg">16/edit-clear-history.svg</file>
<file alias="configure.svg">16/configure.svg</file>
Expand Down
14 changes: 14 additions & 0 deletions src/kirigami_ui/+android/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ Kirigami.ApplicationWindow {
root.pageStack.currentItem.document.open()
}
},
Kirigami.Action {
text: i18nc("Main menu and global menu actions", "&Open remote file")
//iconName: "document-open-remote"
iconSource: "qrc:/icons/document-open-remote.svg"
onTriggered: {
root.onDiscard = Prompter.CloseActions.Network
root.pageStack.currentItem.document.openFromNetwork()
}
},
Kirigami.Action {
text: i18nc("Main menu and global menu actions", "&Save")
iconName: "document-save"
Expand Down Expand Up @@ -338,6 +347,8 @@ Kirigami.ApplicationWindow {
root.pageStack.currentItem.keyConfigurationOverlay.close()
else if (root.pageStack.currentItem.namedMarkerConfiguration.sheetOpen)
root.pageStack.currentItem.namedMarkerConfiguration.close()
else if (root.pageStack.currentItem.networkDialog.sheetOpen)
root.pageStack.currentItem.networkDialog.close()
else if (wheelSettings.sheetOpen)
wheelSettings.close()
// Close find, compare against enabled instead of isOpen to prevent closing find while it is invisible.
Expand Down Expand Up @@ -529,6 +540,9 @@ Kirigami.ApplicationWindow {
case Prompter.CloseActions.Open:
root.pageStack.currentItem.openDialog.open();
break;
case Prompter.CloseActions.Network:
root.pageStack.currentItem.networkDialog.open();
break;
case Prompter.CloseActions.Quit: Qt.quit();
break;
case Prompter.CloseActions.Ignore:
Expand Down
14 changes: 14 additions & 0 deletions src/kirigami_ui/+windows/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ Kirigami.ApplicationWindow {
root.pageStack.currentItem.document.open()
}
},
Kirigami.Action {
text: i18nc("Main menu and global menu actions", "&Open remote file")
//iconName: "document-open-remote"
iconSource: "qrc:/icons/document-open-remote.svg"
onTriggered: {
root.onDiscard = Prompter.CloseActions.Network
root.pageStack.currentItem.document.openFromNetwork()
}
},
Kirigami.Action {
text: i18nc("Main menu and global menu actions", "&Save")
iconName: "document-save"
Expand Down Expand Up @@ -380,6 +389,8 @@ Kirigami.ApplicationWindow {
root.pageStack.currentItem.keyConfigurationOverlay.close()
else if (root.pageStack.currentItem.namedMarkerConfiguration.sheetOpen)
root.pageStack.currentItem.namedMarkerConfiguration.close()
else if (root.pageStack.currentItem.networkDialog.sheetOpen)
root.pageStack.currentItem.networkDialog.close()
else if (wheelSettings.sheetOpen)
wheelSettings.close()
// Close find, compare against enabled instead of isOpen to prevent closing find while it is invisible.
Expand Down Expand Up @@ -605,6 +616,9 @@ Kirigami.ApplicationWindow {
case Prompter.CloseActions.Open:
root.pageStack.currentItem.openDialog.open();
break;
case Prompter.CloseActions.Network:
root.pageStack.currentItem.networkDialog.open();
break;
case Prompter.CloseActions.Quit: Qt.quit();
break;
case Prompter.CloseActions.Ignore:
Expand Down
13 changes: 13 additions & 0 deletions src/kirigami_ui/EditorToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1107,5 +1107,18 @@ ToolBar {
}
}
}
RowLayout {
Button {
visible: networkDialog.autoReloadRunning
text: i18nc("Next reload starts at 10:11:12", "Next reload starts at <pre>%1</pre>", networkDialog.nextReloadTime)
onClicked: networkDialog.open()
flat: true
contentItem: Loader { sourceComponent: textComponent }
Layout.topMargin: -8
Layout.bottomMargin: -32
Layout.rightMargin: 3
Layout.leftMargin: showSliderIcons ? 1 : 8
}
}
}
}
170 changes: 170 additions & 0 deletions src/kirigami_ui/PrompterPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Dialogs 1.3
import Qt.labs.settings 1.0
//import Qt.labs.platform 1.1 as Labs

import com.cuperino.qprompt.markers 1.0
Expand All @@ -42,6 +43,7 @@ Kirigami.Page {
property alias overlay: viewport.overlay
property alias document: viewport.document
property alias openDialog: viewport.openDialog
property alias networkDialog: networkDialog
property alias prompterBackground: viewport.prompterBackground
property alias find: viewport.find
property alias keyConfigurationOverlay: keyConfigurationOverlay
Expand Down Expand Up @@ -1003,6 +1005,174 @@ Kirigami.Page {
}
}

Settings {
category: "networkDialog"
property alias url: openUrl.text
property alias autoReload: networkDialog.autoReload
property alias autoReloadHours: autoReloadHours.value
property alias autoReloadMinutes: autoReloadMinutes.value
property alias autoReloadSeconds: autoReloadSeconds.value
}
Timer {
id: autoReloadTimer
running: networkDialog.autoReloadRunning
repeat: true
triggeredOnStart: false
interval: 1000 * (3600 * autoReloadHours.value + 60 * autoReloadMinutes.value + autoReloadSeconds.value)
onTriggered: networkDialog.openFromRemote();
}
Kirigami.OverlaySheet {
id: networkDialog
header: Kirigami.Heading {
text: i18n("Open from network...")
level: 1
}
property bool autoReload: false
property bool autoReloadRunning: false
property string nextReloadTime: ""
function updateNextReloadTime() {
const date = new Date();
date.setTime(date.getTime() + autoReloadTimer.interval);
nextReloadTime = date.toLocaleTimeString();
}
function openFromRemote() {
document.loadFromNetwork(openUrl.text);
if (!autoReloadRunning)
editor.lastDocument = ""
if (autoReload) {
autoReloadRunning = true;
updateNextReloadTime();
}
}
function disableAutoReload() {
networkDialog.autoReloadRunning = false;
}
ColumnLayout {
width: parent.width
RowLayout {
Label {
text: i18n("URL:")
}
TextField {
id: openUrl
placeholderText: i18n("http, https, and ftp protocols supported")
Layout.fillWidth: true
Layout.leftMargin: Kirigami.Units.smallSpacing
Layout.rightMargin: Kirigami.Units.smallSpacing
onAccepted: networkDialog.openFromRemote()
}
}
RowLayout {
Button {
id: autoReloadToggle
flat: true
text: i18n("Auto reload")
checkable: true
checked: networkDialog.autoReload
onToggled: {
networkDialog.autoReload = checked;
if (!checked)
networkDialog.disableAutoReload();
}
}
Label {
text: i18n("Hours:")
}
SpinBox {
id: autoReloadHours
Layout.fillWidth: true
Layout.leftMargin: Units.SmallSpacing
Layout.rightMargin: Units.SmallSpacing
enabled: networkDialog.autoReload
value: 0
to: 168
onValueModified: {
if (value === to) {
autoReloadMinutes.value = 0;
autoReloadSeconds.value = 0;
}
// Since this onValueModified will get called regardless of which SpinBox gets modified, this is where and when we update the nextReloadTime
networkDialog.updateNextReloadTime();
}
}
Label {
text: i18n("Minutes:")
}
SpinBox {
id: autoReloadMinutes
Layout.fillWidth: true
Layout.leftMargin: Units.SmallSpacing
Layout.rightMargin: Units.SmallSpacing
enabled: networkDialog.autoReload
value: 5
from: value>0 || autoReloadMinutes.value>0 || autoReloadHours.value>0 ? -1 : 0
to: /*autoReloadHours.value===autoReloadHours.to ? 0 :*/ 60
onValueModified: {
if (value < 0) {
value = 59;
--autoReloadHours.value;
}
else if (value > 59) {
value = 0;
++autoReloadHours.value;
}
autoReloadHours.onValueModified();
}
}
Label {
text: i18n("Seconds:")
}
SpinBox {
id: autoReloadSeconds
Layout.fillWidth: true
Layout.leftMargin: Units.SmallSpacing
Layout.rightMargin: Units.SmallSpacing
enabled: networkDialog.autoReload
value: 0
from: value>0 || autoReloadMinutes.value>0 || autoReloadHours.value>0 ? -1 : 1
to: /*autoReloadHours.value===autoReloadHours.to ? 0 :*/ 60
onValueModified: {
if (value < 0) {
value = 59;
--autoReloadMinutes.value;
}
else if (value > 59) {
value = 0;
++autoReloadMinutes.value;
}
autoReloadMinutes.onValueModified();
}
}
}
RowLayout {
Label {
text: autoReloadTimer.running ?
i18nc("Next reload starts at 10:11:12", "Next reload starts at %1", networkDialog.nextReloadTime)
: i18n("Auto reload is not running")
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
}
Button {
enabled: openUrl.text !== ""
flat: true
text: i18n("Load from Network")
onClicked: {
networkDialog.openFromRemote();
networkDialog.close();
}
}
Button {
flat: true
text: i18n("Close")
onClicked: {
networkDialog.close();
viewport.prompter.restoreFocus();
}
}
}
}
}

//Kirigami.OverlaySheet {
//id: stepsConfiguration
//onSheetOpenChanged: {
Expand Down
14 changes: 14 additions & 0 deletions src/kirigami_ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ Kirigami.ApplicationWindow {
root.pageStack.currentItem.document.open()
}
},
Kirigami.Action {
text: i18nc("Main menu and global menu actions", "&Open remote file")
//iconName: "document-open-remote"
iconSource: "qrc:/icons/document-open-remote.svg"
onTriggered: {
root.onDiscard = Prompter.CloseActions.Network
root.pageStack.currentItem.document.openFromNetwork()
}
},
Kirigami.Action {
text: i18nc("Main menu and global menu actions", "&Save")
//iconName: "document-save"
Expand Down Expand Up @@ -397,6 +406,8 @@ Kirigami.ApplicationWindow {
root.pageStack.currentItem.keyConfigurationOverlay.close()
else if (root.pageStack.currentItem.namedMarkerConfiguration.sheetOpen)
root.pageStack.currentItem.namedMarkerConfiguration.close()
else if (root.pageStack.currentItem.networkDialog.sheetOpen)
root.pageStack.currentItem.networkDialog.close()
else if (wheelSettings.sheetOpen)
wheelSettings.close()
// Close find, compare against enabled instead of isOpen to prevent closing find while it is invisible.
Expand Down Expand Up @@ -939,6 +950,9 @@ Kirigami.ApplicationWindow {
case Prompter.CloseActions.Open:
root.pageStack.currentItem.openDialog.open();
break;
case Prompter.CloseActions.Network:
root.pageStack.currentItem.networkDialog.open();
break;
case Prompter.CloseActions.Quit:
Qt.quit();
break;
Expand Down
Loading

0 comments on commit e4301be

Please sign in to comment.