Skip to content

Commit

Permalink
Merge pull request #1 from MarcinOrlowski/dev
Browse files Browse the repository at this point in the history
Release 1.0.1
  • Loading branch information
MarcinOrlowski authored Dec 2, 2020
2 parents 18e863c + 7686d4d commit cab6988
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 13 deletions.
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Binary file modified artwork/state-icons.xcf
Binary file not shown.
37 changes: 37 additions & 0 deletions bin/setup-config.sh
Original file line number Diff line number Diff line change
@@ -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}"
Binary file modified img/config-full.png
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/contents/config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<group name="Connection">
<entry name="api_url" type="String">
<default></default>
<default>{OCTOPRINT_API_URL}</default>
</entry>
<entry name="api_key" type="String">
<default></default>
<default>{OCTOPRINT_API_KEY}</default>
</entry>
<entry name="cameraViewSnapshotUrl" type="String">
<default></default>
<default>{OCTOPRINT_SNAPSHOT_URL}</default>
</entry>
<entry name="statusPollInterval" type="Int">
<default>15</default>
Expand Down
Binary file added src/contents/images/state-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/contents/images/state-dead.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/contents/images/state-disconnected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/contents/images/state-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/contents/images/state-idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/contents/images/state-paused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/contents/images/state-unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/contents/images/state-working.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/contents/ui/configAbout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ColumnLayout {
textFormat: Text.RichText
text:
"<center>
<h2>OctoPrint Monitor v1.0.0</h2><br />
<h2>OctoPrint Monitor v1.0.1</h2><br />
&copy;2020 by Marcin Orlowski<br />
<br />
<a href=\"https://github/com/marcinorlowski/octoprint-monitor\">https://github/com/marcinorlowski/octoprint-monitor</a>
Expand Down
12 changes: 11 additions & 1 deletion src/contents/ui/configFullRepresentation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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") + ':'
}
Expand All @@ -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
Expand Down
28 changes: 22 additions & 6 deletions src/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cab6988

Please sign in to comment.