diff --git a/CHANGES.md b/CHANGES.md index 3c46722..0489137 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,11 @@ ## CHANGE LOG ## +* v1.0.1 (2020-12-01) + * Added `Configuration` state indicating lack of widget required configuration. + * Improved API response handling. + * Scaled state icons down to reduce plasmoid size + * Corected layout of "Full layout" config panel + * v1.0.0 (2020-12-01) * Initial public release - diff --git a/README.md b/README.md index b046a88..5e3ab98 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,11 @@ help you instantly know the state with just quick look. Detailed information are You can face following icons, which representing different type of state. +### Configuration ### + +![Configuration](img/state-configuration.png) The **Configuration** state means plasmoid is yet not configured. The base +miminum it requires is OctoPrint API URL and API access key. See [configuration](#configuration) for more information. + ### Idle ### ![Idle](img/state-idle.png) The **Idle** state means connection to API is good and printer is currently connected to OctoPrint but is not printing anything, sitting idle and wasting electricity. @@ -218,6 +223,7 @@ Full layout is being used when `OctoPrint Monitor` is used as regular desktop wi - **Camera update intervals** - specify how frequently you want webcam snapshot view to be updated. You may want to increase the interval, to reduce network traffic and drop the load off OctoPrint. + - **Camera view control** - **Stop camera polling for state buckets** - if enabled, camera snapshot polling will stop if printer enters selected states. You may want to i.e. enable this option for i.e. "Idle" and "Disconnected" states as most likely there will be nothing diff --git a/artwork/state-icons.xcf b/artwork/state-icons.xcf index b5ff487..02bbef0 100644 Binary files a/artwork/state-icons.xcf and b/artwork/state-icons.xcf differ diff --git a/bin/setup-config.sh b/bin/setup-config.sh new file mode 100755 index 0000000..3c84302 --- /dev/null +++ b/bin/setup-config.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +function escape() { + local -r str="${1:-}" + echo $(echo "${str}" | sed -e 's/[]\/$*.^[]/\\&/g') +} + +declare -r src_dir="src" + + +if [[ ! -d "${src_dir}" ]]; then + echo "*** Source dir not found: ${src_dir}" + exit 1 +fi + +declare -r cfg_template_file="${src_dir}/contents/config/main-template.xml" +declare -r cfg_config_file="${src_dir}/contents/config/main.xml" + +if [[ ! -s "${cfg_template_file}" ]]; then + echo "*** Config template not found: ${cfg_template_file}" + exit 1 +fi + +op_api_url= +op_api_key= +op_snapshot_url= + +if [[ "$#" -gt 0 ]]; then + echo "Populating config with env vars: ${cfg_config_file}" + op_api_url=$(escape "${OCTOPRINT_API_URL}") + op_api_key=$(escape "${OCTOPRINT_API_KEY}") + op_snapshot_url=$(escape "${OCTOPRINT_SNAPSHOT_URL}") +else + echo "Creating empty config file: ${cfg_config_file}" +fi + +cat "${cfg_template_file}" | sed -e "s/{OCTOPRINT_API_URL}/${op_api_url}/g" | sed -e "s/{OCTOPRINT_API_KEY}/${op_api_key}/g" | sed -e "s/{OCTOPRINT_SNAPSHOT_URL}/${op_snapshot_url}/g" > "${cfg_config_file}" diff --git a/img/config-full.png b/img/config-full.png index b8050ab..1a30bdc 100644 Binary files a/img/config-full.png and b/img/config-full.png differ diff --git a/src/contents/config/.gitignore b/src/contents/config/.gitignore new file mode 100644 index 0000000..7a6f9e7 --- /dev/null +++ b/src/contents/config/.gitignore @@ -0,0 +1 @@ +main.xml diff --git a/src/contents/config/main.xml b/src/contents/config/main-template.xml similarity index 96% rename from src/contents/config/main.xml rename to src/contents/config/main-template.xml index e0820b6..c76a6c5 100644 --- a/src/contents/config/main.xml +++ b/src/contents/config/main-template.xml @@ -6,13 +6,13 @@ - + {OCTOPRINT_API_URL} - + {OCTOPRINT_API_KEY} - + {OCTOPRINT_SNAPSHOT_URL} 15 diff --git a/src/contents/images/state-configuration.png b/src/contents/images/state-configuration.png new file mode 100644 index 0000000..3d1a242 Binary files /dev/null and b/src/contents/images/state-configuration.png differ diff --git a/src/contents/images/state-dead.png b/src/contents/images/state-dead.png index 2a0c666..7ce51f6 100644 Binary files a/src/contents/images/state-dead.png and b/src/contents/images/state-dead.png differ diff --git a/src/contents/images/state-disconnected.png b/src/contents/images/state-disconnected.png index 72941eb..bd68242 100644 Binary files a/src/contents/images/state-disconnected.png and b/src/contents/images/state-disconnected.png differ diff --git a/src/contents/images/state-error.png b/src/contents/images/state-error.png index f764a45..4700630 100644 Binary files a/src/contents/images/state-error.png and b/src/contents/images/state-error.png differ diff --git a/src/contents/images/state-idle.png b/src/contents/images/state-idle.png index c7aaafa..1e60708 100644 Binary files a/src/contents/images/state-idle.png and b/src/contents/images/state-idle.png differ diff --git a/src/contents/images/state-paused.png b/src/contents/images/state-paused.png index da17483..552542a 100644 Binary files a/src/contents/images/state-paused.png and b/src/contents/images/state-paused.png differ diff --git a/src/contents/images/state-unknown.png b/src/contents/images/state-unknown.png index 5bb7f3c..6aebe91 100644 Binary files a/src/contents/images/state-unknown.png and b/src/contents/images/state-unknown.png differ diff --git a/src/contents/images/state-working.png b/src/contents/images/state-working.png index 9576f7f..2ab67bd 100644 Binary files a/src/contents/images/state-working.png and b/src/contents/images/state-working.png differ diff --git a/src/contents/ui/configAbout.qml b/src/contents/ui/configAbout.qml index 950e191..d141a8f 100644 --- a/src/contents/ui/configAbout.qml +++ b/src/contents/ui/configAbout.qml @@ -36,7 +36,7 @@ ColumnLayout { textFormat: Text.RichText text: "
-

OctoPrint Monitor v1.0.0


+

OctoPrint Monitor v1.0.1


©2020 by Marcin Orlowski

https://github/com/marcinorlowski/octoprint-monitor diff --git a/src/contents/ui/configFullRepresentation.qml b/src/contents/ui/configFullRepresentation.qml index 7e4e877..81f5246 100644 --- a/src/contents/ui/configFullRepresentation.qml +++ b/src/contents/ui/configFullRepresentation.qml @@ -41,7 +41,7 @@ ColumnLayout { anchors.left: parent.left anchors.right: parent.right - CheckBox { + PlasmaComponents.CheckBox { id: cameraViewEnabled Kirigami.FormData.label: i18n("Enable camera snapshot view") + ':' } @@ -63,6 +63,16 @@ ColumnLayout { Kirigami.FormData.label: i18n("Camera update interval (seconds)") + ':' } + } + } + + GroupBox { + title: i18n("Camera view control") + Layout.fillWidth: true + + Kirigami.FormLayout { + anchors.left: parent.left + anchors.right: parent.right PlasmaComponents.CheckBox { id: stopCameraPollForBuckets diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index 9574d71..ba9c899 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -72,6 +72,9 @@ Item { // Indicates we were able to successfuly connect to OctoPrint API property bool apiConnected: false + // Tells if plasmoid API access is already confugred. + property bool apiAccessConfigured: false; + // ------------------------------------------------------------------------------------------------------------------------ property bool firstApiRequest: true @@ -195,6 +198,8 @@ Item { // case bucket_error: "error" case 'unavailable': desc = 'Unable to connect to OctoPrint API.'; break; case 'connecting': desc = 'Connecting to OctoPrint API.'; break; + + case 'configuration': desc = 'Widget is not configured!'; break; } } @@ -209,14 +214,15 @@ Item { var printerConnected = isPrinterConnected(); var state = getPrinterStateBucket(); + main.apiAccessConfigured = (plasmoid.configuration.api_url != '' && plasmoid.configuration.api_key != ''); + if (main.apiConnected) { jobInProgress = isJobInProgress(); if (jobInProgress && main.jobState == "printing") { state = main.jobState; } } else { - state = 'unavailable'; - + state = (!main.apiAccessConfigured) ? 'configuration' : 'unavailable'; } main.jobInProgress = jobInProgress; @@ -243,7 +249,9 @@ Item { */ function getOctoStateIcon() { var bucket = 'dead'; - if (main.apiConnected) { + if (!main.apiAccessConfigured) { + bucket = 'configuration'; + } else if (main.apiConnected) { bucket = getPrinterStateBucket(); } return plasmoid.file("", "images/state-" + bucket + ".png"); @@ -262,9 +270,7 @@ Item { var apiUrl = plasmoid.configuration.api_url; var apiKey = plasmoid.configuration.api_key; - if ( apiUrl + apiKey == "" ) { - throw new Error('Error: API access is not configured.'); - } + if ( apiUrl + apiKey == "" ) return null; var xhr = new XMLHttpRequest(); var url = apiUrl + "/" + req; @@ -286,6 +292,11 @@ Item { function getJobStateFromApi() { var xhr = getXhr('job'); + if (xhr === null) { + updateOctoState(); + return; + } + xhr.onreadystatechange = (function () { // We only care about DONE readyState. if (xhr.readyState !== 4) return; @@ -349,6 +360,11 @@ Item { function getPrinterStateFromApi() { var xhr = getXhr('printer'); + if (xhr === null) { + updateOctoState(); + return; + } + xhr.onreadystatechange = (function () { // We only care about DONE readyState. if (xhr.readyState !== 4) return; diff --git a/src/metadata.desktop b/src/metadata.desktop index 66bd6df..b9e3425 100644 --- a/src/metadata.desktop +++ b/src/metadata.desktop @@ -10,7 +10,7 @@ X-KDE-PluginInfo-Author=Marcin Orlowski X-KDE-PluginInfo-Email= X-KDE-PluginInfo-License=MIT X-KDE-PluginInfo-Name=com.marcinorlowski.octoprint-monitor -X-KDE-PluginInfo-Version=1.0.0 +X-KDE-PluginInfo-Version=1.0.1 X-KDE-PluginInfo-Website=https://github.com/MarcinOrlowski/octoprint-monitor X-KDE-ServiceTypes=Plasma/Applet X-Plasma-API=declarativeappletscript