Compare commits
24 Commits
8bb97ed926
...
v0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| f4fd1b1b07 | |||
| a150958960 | |||
| 819d349bae | |||
| 0ae6c3f593 | |||
| 945e3212cf | |||
| 3547207eca | |||
| 6669e6722a | |||
| 7524745b18 | |||
| a9c5139d55 | |||
| 7cc6056e7e | |||
| 7516eb4444 | |||
| ef2403b3cd | |||
| 7a0bb14df4 | |||
|
|
3cb2d9cb3e | ||
|
|
5317215c13 | ||
|
|
8d7e82bea5 | ||
|
|
4813941a5c | ||
|
|
190ff6a508 | ||
|
|
cf45a045ff | ||
|
|
87315a7bda | ||
|
|
88f2a02652 | ||
|
|
b45e7dbda9 | ||
|
|
d7a3088712 | ||
|
|
9532178b4c |
99
.drone.yml
Normal file
99
.drone.yml
Normal file
@@ -0,0 +1,99 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build
|
||||
|
||||
steps:
|
||||
- name: build-deb-amd64
|
||||
image: cache.coadcorp.com/library/buildpack-deps:jammy
|
||||
environment:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
commands:
|
||||
- apt-get update
|
||||
- apt-get install -y --no-install-recommends build-essential qt5-qmake qtbase5-dev qtbase5-dev-tools libexif-dev qt5-image-formats-plugins libmosquitto-dev dpkg-dev fakeroot ca-certificates
|
||||
- ARCH=amd64 BUILD_DIR=build-amd64 bash sbin/build_deb.sh "${DRONE_TAG:-${DRONE_COMMIT_SHA:0:8}}"
|
||||
- ls -la dist
|
||||
|
||||
- name: build-deb-armhf
|
||||
image: cache.coadcorp.com/library/buildpack-deps:jammy
|
||||
environment:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
ARM_CFLAGS: -march=armv6 -mfpu=vfp -mfloat-abi=hard -marm
|
||||
commands:
|
||||
- dpkg --add-architecture armhf
|
||||
- |
|
||||
cat > /etc/apt/sources.list <<'EOF'
|
||||
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
|
||||
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
|
||||
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
|
||||
deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
|
||||
deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy main restricted universe multiverse
|
||||
deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted universe multiverse
|
||||
deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse
|
||||
deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted universe multiverse
|
||||
EOF
|
||||
- apt-get update
|
||||
- apt-get install -y --no-install-recommends build-essential qt5-qmake qtbase5-dev qtbase5-dev-tools libexif-dev qt5-image-formats-plugins libmosquitto-dev dpkg-dev fakeroot ca-certificates gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf qtbase5-dev:armhf libqt5core5a:armhf libqt5gui5:armhf libqt5widgets5:armhf libqt5network5:armhf libexif-dev:armhf libmosquitto-dev:armhf qt5-image-formats-plugins:armhf
|
||||
- ARCH=armhf BUILD_DIR=build-armhf QMAKESPEC=$PWD/mkspecs/linux-armhf-g++ QMAKE_QTCONF=$PWD/mkspecs/qt-armhf.conf QMAKE_CFLAGS="$ARM_CFLAGS" QMAKE_CXXFLAGS="$ARM_CFLAGS" bash sbin/build_deb.sh "${DRONE_TAG:-${DRONE_COMMIT_SHA:0:8}}"
|
||||
- ls -la dist
|
||||
|
||||
- name: build-deb-arm64
|
||||
image: cache.coadcorp.com/library/buildpack-deps:jammy
|
||||
environment:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
ARM64_CFLAGS: -march=armv8-a
|
||||
commands:
|
||||
- dpkg --add-architecture arm64
|
||||
- |
|
||||
cat > /etc/apt/sources.list <<'EOF'
|
||||
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
|
||||
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
|
||||
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
|
||||
deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
|
||||
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted universe multiverse
|
||||
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted universe multiverse
|
||||
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse
|
||||
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted universe multiverse
|
||||
EOF
|
||||
- apt-get update
|
||||
- apt-get install -y --no-install-recommends build-essential qt5-qmake qtbase5-dev qtbase5-dev-tools libexif-dev qt5-image-formats-plugins libmosquitto-dev dpkg-dev fakeroot ca-certificates gcc-aarch64-linux-gnu g++-aarch64-linux-gnu qtbase5-dev:arm64 libqt5core5a:arm64 libqt5gui5:arm64 libqt5widgets5:arm64 libqt5network5:arm64 libexif-dev:arm64 libmosquitto-dev:arm64 qt5-image-formats-plugins:arm64
|
||||
- ARCH=arm64 BUILD_DIR=build-arm64 QMAKESPEC=$PWD/mkspecs/linux-arm64-g++ QMAKE_QTCONF=$PWD/mkspecs/qt-arm64.conf QMAKE_CFLAGS="$ARM64_CFLAGS" QMAKE_CXXFLAGS="$ARM64_CFLAGS" bash sbin/build_deb.sh "${DRONE_TAG:-${DRONE_COMMIT_SHA:0:8}}"
|
||||
- ls -la dist
|
||||
|
||||
- name: build-deps-image
|
||||
image: cache.coadcorp.com/plugins/docker
|
||||
settings:
|
||||
registry: registry.coadcorp.com
|
||||
repo: slide/build-deps
|
||||
dockerfile: Dockerfile.builddeps
|
||||
username:
|
||||
from_secret: REGISTRY_USER
|
||||
password:
|
||||
from_secret: REGISTRY_PASS
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_COMMIT_SHA}
|
||||
when:
|
||||
event:
|
||||
- promote
|
||||
target:
|
||||
- build-deps
|
||||
|
||||
- name: gitea-release
|
||||
image: cache.coadcorp.com/plugins/gitea-release
|
||||
depends_on:
|
||||
- build-deb-amd64
|
||||
- build-deb-armhf
|
||||
- build-deb-arm64
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: GITEA_TOKEN
|
||||
base_url: https://git.coadcorp.com
|
||||
files:
|
||||
- dist/*.deb
|
||||
draft: false
|
||||
prerelease: false
|
||||
title: ${DRONE_TAG}
|
||||
note: Automated release for ${DRONE_TAG}
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ make
|
||||
.git
|
||||
build
|
||||
.vscode
|
||||
test_config/slide.options.json
|
||||
|
||||
17
Dockerfile.builddeps
Normal file
17
Dockerfile.builddeps
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM cache.coadcorp.com/library/ubuntu:22.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
qt5-qmake \
|
||||
qtbase5-dev \
|
||||
qtbase5-dev-tools \
|
||||
libexif-dev \
|
||||
qt5-image-formats-plugins \
|
||||
libmosquitto-dev \
|
||||
dpkg-dev \
|
||||
fakeroot \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
3
Makefile
3
Makefile
@@ -7,7 +7,7 @@ all: build
|
||||
|
||||
.PHONY: install-deps-deb
|
||||
install-deps-deb:
|
||||
apt install qt5-qmake libexif12 qt5-default libexif-dev qt5-image-formats-plugins
|
||||
apt install qt5-qmake libexif12 qt5-default libexif-dev qt5-image-formats-plugins libmosquitto-dev
|
||||
|
||||
check-deps-deb:
|
||||
dpkg -l | grep qt5-qmake
|
||||
@@ -15,6 +15,7 @@ check-deps-deb:
|
||||
dpkg -l | grep libexif-dev
|
||||
dpkg -l | grep qt5-default
|
||||
dpkg -l | grep qt5-image-formats-plugins
|
||||
dpkg -l | grep libmosquitto-dev
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
||||
90
README.md
90
README.md
@@ -18,7 +18,7 @@ This project is maintained by myself during my spare time. If you like and use i
|
||||
## Usage
|
||||
|
||||
```
|
||||
slide [-t rotation_seconds] [-a aspect] [-o background_opacity(0..255)] [-b blur_radius] [-p image_folder|-i imageFile,...] [-r] [-O overlay_string] [-v] [--verbose] [--stretch] [-c path_to_config_json]
|
||||
slide [-t rotation_seconds] [-T transition_seconds] [-h/--overlay-color overlay_color(#rrggbb)] [-a aspect] [-o background_opacity(0..255)] [-b blur_radius] [-p image_folder|-i imageFile,...] [-r] [-O overlay_string] [-v] [--verbose] [--stretch] [-c path_to_config_json]
|
||||
```
|
||||
|
||||
* `image_folder`: where to search for images (.jpg files)
|
||||
@@ -30,10 +30,13 @@ slide [-t rotation_seconds] [-a aspect] [-o background_opacity(0..255)] [-b blur
|
||||
* `-S` for sorted rotation (files ordered by name, first images then subfolders)
|
||||
* `rotation_seconds(default=30)`: time until next random image is chosen from the given folder
|
||||
* `aspect(default=a)`: the required aspect ratio of the picture to display. Valid values are 'a' (all), 'l' (landscape), 'p' (portrait) and 'm' (monitor). Monitor will match the aspect ratio of the display we are running on.
|
||||
* `transition_seconds(default=1)`: time of image transition animation. Default is 1 second, and transition animation will be disabled if the value is set to 0
|
||||
* `aspect(default=a)`: the required aspect ratio of the picture to display. Valid values are 'a' (all), 'l' (landscape) and 'p' (portrait)
|
||||
* `background_opacity(default=150)`: opacity of the background filling image between 0 (black background) and 255
|
||||
* `blur_radius(default=20)`: blur radius of the background filling image
|
||||
* `-v` or `--verbose`: Verbose debug output when running, plus a thumbnail of the original image in the bottom left of the screen
|
||||
* `--stretch`: When in aspect mode 'l','p' or 'm' crop the image rather than leaving a blurred background. For example, in landscape mode this will make images as wide as the screen and crop the top and bottom to fit.
|
||||
* `-h` or `--overlay-color` the color of the overlay text, in the form of 3 or 6 digits hex rgb string prefixed by `#`, for example `#00FF00` or `#0F0` for color 🟢
|
||||
* `-O` is used to create a overlay string.
|
||||
* It defines overlays for all four edges in the order `top-left;top-right;bottom-left;bottom-right`
|
||||
* All edges overlays are separated by `;`
|
||||
@@ -49,7 +52,6 @@ slide [-t rotation_seconds] [-a aspect] [-o background_opacity(0..255)] [-b blur
|
||||
* `<dir>`directory of the current image
|
||||
* `<path>`path to the current image without filename
|
||||
* Example: `slide -p ./images -O "20|60|Time: <time>;;;Picture taken at <exifdatetime>"`
|
||||
|
||||
To exit the application, press escape. If you're using a touch display, touch all 4 corners at the same time.
|
||||
|
||||
## Configuration file
|
||||
@@ -109,18 +111,99 @@ Supported keys and values in the JSON configuration are:
|
||||
* `overlay` : the same as the overlay command line argument
|
||||
* `shuffle` : set to true to enable shuffle mode for file display
|
||||
* `recursive` : set to true to enable recursive mode for file display
|
||||
* `sorted` : set to true to enable shuffle mode for file display
|
||||
* `sorted` : set to true to enable sorted mode for file display
|
||||
* `stretch` : set to true to enable, the same as the `--stretch` command line argument
|
||||
* `rotationSeconds` : the same as the `-t` command line argument
|
||||
* `opacity` : the same as the command line `-o` argument
|
||||
* `blur` : the same as the command line `-b` argument
|
||||
* `debug` : set to true to enable verbose output from the program
|
||||
* `mqtt` : MQTT playback control (see below)
|
||||
* `immich` : connect to an Immich server instead of a local path (see below)
|
||||
* `scheduler` : this entry is an array of possible path values and associated settings. This key lets you manage display times/settings for a collection of paths. In the example above the top entry shows ONLY files from a Redit feed between 2 and 4pm, ONLY files from the `show_peak_times` folder from 8am to 10am and then 4pm to 7pm. At all other times it alternates displaying files in the `always_show_1` and `always_show_2` folder.
|
||||
* `exclusive` : When set to `true` only this entry will be used when it is in its valid time window.
|
||||
* `times` : times is a JSON array of start and end times in which it is valid to display this image. The time is in the format HH:MM:SS and is based on the systems local time. If `start` isn't defined then it defaults to the start of the day, if `end` isn't defined it defaults to the end of the day.
|
||||
* `path` : the path to image files
|
||||
* `stretch` : as above
|
||||
|
||||
### MQTT control
|
||||
|
||||
Add an `mqtt` block to control playback remotely. Publish one of the commands below to the configured topic.
|
||||
|
||||
Example:
|
||||
```
|
||||
{
|
||||
"mqtt": {
|
||||
"host": "mqtt.local",
|
||||
"port": 1883,
|
||||
"topic": "slide/control",
|
||||
"clientId": "slide-frame",
|
||||
"username": "slide",
|
||||
"password": "secret",
|
||||
"keepAlive": 30,
|
||||
"qos": 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Commands:
|
||||
* `play` / `resume` — resume slideshow
|
||||
* `pause` — pause slideshow
|
||||
* `next` / `next-image` — advance to next image
|
||||
* `next-folder` — jump to next configured path (if multiple paths are configured)
|
||||
* `restart` / `reset` — recreate the selector and restart playback
|
||||
|
||||
### Immich configuration (lightweight + low power)
|
||||
|
||||
Immich uses an API key and a `/api` base path. This integration requests the asset search endpoint and downloads the configured image size into a local cache before displaying them. That keeps bandwidth and power usage low while still letting `slide` do its normal scaling and transitions.
|
||||
|
||||
Example (single source):
|
||||
```
|
||||
{
|
||||
"immich": {
|
||||
"url": "http://immich.local:2283",
|
||||
"apiKey": "IMMICH_API_KEY",
|
||||
"albumId": "b7f3c8b2-2e3f-4b32-9dc9-8c3f8b0a3ef7",
|
||||
"size": "fullsize",
|
||||
"order": "desc",
|
||||
"pageSize": 200,
|
||||
"maxAssets": 1000,
|
||||
"cachePath": "~/.cache/slide/immich",
|
||||
"cacheMaxMB": 512,
|
||||
"includeArchived": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Example (scheduler entry):
|
||||
```
|
||||
{
|
||||
"scheduler": [
|
||||
{
|
||||
"exclusive": true,
|
||||
"immich": {
|
||||
"url": "http://immich.local:2283",
|
||||
"apiKey": "IMMICH_API_KEY",
|
||||
"albumIds": ["b7f3c8b2-2e3f-4b32-9dc9-8c3f8b0a3ef7"],
|
||||
"size": "fullsize"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Immich settings:
|
||||
* `url`: base Immich server URL (the integration appends `/api` automatically if missing).
|
||||
* `apiKey`: Immich API key (needs `asset.view`, and `asset.download` if `size` is `original`).
|
||||
* `albumId` or `albumIds`: optional album filters.
|
||||
* `size`: `"fullsize"`, `"preview"`, `"thumbnail"`, or `"original"` (original uses the download endpoint).
|
||||
* `order`: `"asc"` or `"desc"` ordering for asset search.
|
||||
* `pageSize`: assets fetched per page.
|
||||
* `maxAssets`: cap on total assets fetched (0 means no cap).
|
||||
* `cachePath`: local cache directory for downloaded images.
|
||||
* `cacheMaxMB`: maximum cache size in MB (0 disables cleanup).
|
||||
* `includeArchived`: include archived assets in search results.
|
||||
When `immich` is set on an entry, `path` and `imageList` are ignored.
|
||||
|
||||
## Folder Options file
|
||||
When using the default or recursive folder mode we support having per folder display options. The options are stored in a file called "options.json" in the images folder and support a subset of the applications configuration settings:
|
||||
```
|
||||
@@ -150,6 +233,7 @@ See the `Configuration File` section for details of each setting.
|
||||
* qt5
|
||||
* qt5-image-formats-plugins
|
||||
* libexif
|
||||
* libmosquitto-dev
|
||||
|
||||
Ubuntu/Raspbian:
|
||||
|
||||
|
||||
21
mkspecs/linux-arm64-g++/qmake.conf
Normal file
21
mkspecs/linux-arm64-g++/qmake.conf
Normal file
@@ -0,0 +1,21 @@
|
||||
exists(/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qmake.conf) {
|
||||
include(/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qmake.conf)
|
||||
} else: exists(/usr/share/qt5/mkspecs/linux-g++/qmake.conf) {
|
||||
include(/usr/share/qt5/mkspecs/linux-g++/qmake.conf)
|
||||
} else: exists($$[QT_HOST_DATA]/mkspecs/linux-g++/qmake.conf) {
|
||||
include($$[QT_HOST_DATA]/mkspecs/linux-g++/qmake.conf)
|
||||
} else {
|
||||
include($$[QT_INSTALL_DATA]/mkspecs/linux-g++/qmake.conf)
|
||||
}
|
||||
|
||||
QMAKE_CC = aarch64-linux-gnu-gcc
|
||||
QMAKE_CXX = aarch64-linux-gnu-g++
|
||||
QMAKE_LINK = aarch64-linux-gnu-g++
|
||||
QMAKE_AR = aarch64-linux-gnu-ar cqs
|
||||
QMAKE_STRIP = aarch64-linux-gnu-strip
|
||||
|
||||
QMAKE_INCDIR_QT = /usr/include/aarch64-linux-gnu/qt5
|
||||
QMAKE_LIBDIR_QT = /usr/lib/aarch64-linux-gnu
|
||||
QMAKE_INCDIR += /usr/include/aarch64-linux-gnu/qt5
|
||||
QMAKE_LIBDIR += /usr/lib/aarch64-linux-gnu
|
||||
QMAKE_LFLAGS += -Wl,-rpath-link,/usr/lib/aarch64-linux-gnu
|
||||
1
mkspecs/linux-arm64-g++/qplatformdefs.h
Normal file
1
mkspecs/linux-arm64-g++/qplatformdefs.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qplatformdefs.h"
|
||||
21
mkspecs/linux-armhf-g++/qmake.conf
Normal file
21
mkspecs/linux-armhf-g++/qmake.conf
Normal file
@@ -0,0 +1,21 @@
|
||||
exists(/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qmake.conf) {
|
||||
include(/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qmake.conf)
|
||||
} else: exists(/usr/share/qt5/mkspecs/linux-g++/qmake.conf) {
|
||||
include(/usr/share/qt5/mkspecs/linux-g++/qmake.conf)
|
||||
} else: exists($$[QT_HOST_DATA]/mkspecs/linux-g++/qmake.conf) {
|
||||
include($$[QT_HOST_DATA]/mkspecs/linux-g++/qmake.conf)
|
||||
} else {
|
||||
include($$[QT_INSTALL_DATA]/mkspecs/linux-g++/qmake.conf)
|
||||
}
|
||||
|
||||
QMAKE_CC = arm-linux-gnueabihf-gcc
|
||||
QMAKE_CXX = arm-linux-gnueabihf-g++
|
||||
QMAKE_LINK = arm-linux-gnueabihf-g++
|
||||
QMAKE_AR = arm-linux-gnueabihf-ar cqs
|
||||
QMAKE_STRIP = arm-linux-gnueabihf-strip
|
||||
|
||||
QMAKE_INCDIR_QT = /usr/include/arm-linux-gnueabihf/qt5
|
||||
QMAKE_LIBDIR_QT = /usr/lib/arm-linux-gnueabihf
|
||||
QMAKE_INCDIR += /usr/include/arm-linux-gnueabihf/qt5
|
||||
QMAKE_LIBDIR += /usr/lib/arm-linux-gnueabihf
|
||||
QMAKE_LFLAGS += -Wl,-rpath-link,/usr/lib/arm-linux-gnueabihf
|
||||
1
mkspecs/linux-armhf-g++/qplatformdefs.h
Normal file
1
mkspecs/linux-armhf-g++/qplatformdefs.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qplatformdefs.h"
|
||||
11
mkspecs/qt-arm64.conf
Normal file
11
mkspecs/qt-arm64.conf
Normal file
@@ -0,0 +1,11 @@
|
||||
[Paths]
|
||||
Prefix=/usr
|
||||
Headers=/usr/include/aarch64-linux-gnu/qt5
|
||||
Libraries=/usr/lib/aarch64-linux-gnu
|
||||
ArchData=/usr/lib/aarch64-linux-gnu/qt5
|
||||
Data=/usr/lib/aarch64-linux-gnu/qt5
|
||||
Plugins=/usr/lib/aarch64-linux-gnu/qt5/plugins
|
||||
HostPrefix=/usr
|
||||
HostData=/usr/lib/x86_64-linux-gnu/qt5
|
||||
HostBinaries=/usr/lib/qt5/bin
|
||||
HostLibraries=/usr/lib/x86_64-linux-gnu
|
||||
11
mkspecs/qt-armhf.conf
Normal file
11
mkspecs/qt-armhf.conf
Normal file
@@ -0,0 +1,11 @@
|
||||
[Paths]
|
||||
Prefix=/usr
|
||||
Headers=/usr/include/arm-linux-gnueabihf/qt5
|
||||
Libraries=/usr/lib/arm-linux-gnueabihf
|
||||
ArchData=/usr/lib/arm-linux-gnueabihf/qt5
|
||||
Data=/usr/lib/arm-linux-gnueabihf/qt5
|
||||
Plugins=/usr/lib/arm-linux-gnueabihf/qt5/plugins
|
||||
HostPrefix=/usr
|
||||
HostData=/usr/lib/x86_64-linux-gnu/qt5
|
||||
HostBinaries=/usr/lib/qt5/bin
|
||||
HostLibraries=/usr/lib/x86_64-linux-gnu
|
||||
69
sbin/build_deb.sh
Normal file
69
sbin/build_deb.sh
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
VERSION="${1:-${VERSION:-0.0.0}}"
|
||||
VERSION="${VERSION#v}"
|
||||
# Debian versions must start with a digit; fall back to 0.0.0+<sha/tag>.
|
||||
if [[ ! "$VERSION" =~ ^[0-9] ]]; then
|
||||
VERSION="0.0.0+${VERSION}"
|
||||
fi
|
||||
ARCH="${ARCH:-$(dpkg --print-architecture)}"
|
||||
BUILD_DIR="${BUILD_DIR:-$ROOT_DIR/build-$ARCH}"
|
||||
DIST_DIR="$ROOT_DIR/dist"
|
||||
STAGE_DIR="$BUILD_DIR/deb"
|
||||
QMAKE_BIN="${QMAKE_BIN:-qmake}"
|
||||
MAKE_JOBS="${MAKE_JOBS:-2}"
|
||||
|
||||
QMAKE_ARGS=()
|
||||
if [[ -n "${QMAKESPEC:-}" ]]; then
|
||||
QMAKE_ARGS+=("-spec" "$QMAKESPEC")
|
||||
fi
|
||||
if [[ -n "${QMAKE_QTCONF:-}" ]]; then
|
||||
QMAKE_ARGS+=("-qtconf" "$QMAKE_QTCONF")
|
||||
fi
|
||||
if [[ -n "${QMAKE_CC:-}" ]]; then
|
||||
QMAKE_ARGS+=("QMAKE_CC=$QMAKE_CC")
|
||||
fi
|
||||
if [[ -n "${QMAKE_CXX:-}" ]]; then
|
||||
QMAKE_ARGS+=("QMAKE_CXX=$QMAKE_CXX")
|
||||
fi
|
||||
if [[ -n "${QMAKE_LINK:-}" ]]; then
|
||||
QMAKE_ARGS+=("QMAKE_LINK=$QMAKE_LINK")
|
||||
fi
|
||||
if [[ -n "${QMAKE_CFLAGS:-}" ]]; then
|
||||
QMAKE_ARGS+=("QMAKE_CFLAGS=$QMAKE_CFLAGS")
|
||||
fi
|
||||
if [[ -n "${QMAKE_CXXFLAGS:-}" ]]; then
|
||||
QMAKE_ARGS+=("QMAKE_CXXFLAGS=$QMAKE_CXXFLAGS")
|
||||
fi
|
||||
if [[ -n "${QMAKE_LFLAGS:-}" ]]; then
|
||||
QMAKE_ARGS+=("QMAKE_LFLAGS=$QMAKE_LFLAGS")
|
||||
fi
|
||||
|
||||
PACKAGE_NAME="slide"
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
mkdir -p "$BUILD_DIR"
|
||||
"$QMAKE_BIN" "${QMAKE_ARGS[@]}" "$ROOT_DIR/src/slide.pro" -o "$BUILD_DIR/Makefile"
|
||||
make -C "$BUILD_DIR" -j"$MAKE_JOBS"
|
||||
|
||||
rm -rf "$STAGE_DIR"
|
||||
mkdir -p "$STAGE_DIR/DEBIAN" "$STAGE_DIR/usr/local/bin" "$DIST_DIR"
|
||||
|
||||
install -m 0755 "$BUILD_DIR/slide" "$STAGE_DIR/usr/local/bin/slide"
|
||||
|
||||
cat > "$STAGE_DIR/DEBIAN/control" <<EOF
|
||||
Package: ${PACKAGE_NAME}
|
||||
Version: ${VERSION}
|
||||
Section: graphics
|
||||
Priority: optional
|
||||
Architecture: ${ARCH}
|
||||
Maintainer: slide build
|
||||
Depends: libqt5core5a, libqt5gui5, libqt5widgets5, libqt5network5, libexif12, qt5-image-formats-plugins, libmosquitto1
|
||||
Description: Lightweight slideshow for photo frames
|
||||
Simple, lightweight slideshow designed for low power devices.
|
||||
EOF
|
||||
|
||||
dpkg-deb --build "$STAGE_DIR" "$DIST_DIR/${PACKAGE_NAME}_${VERSION}_${ARCH}.deb"
|
||||
@@ -48,7 +48,109 @@ void SetJSONBool(bool &value, QJsonObject jsonDoc, const char *key) {
|
||||
}
|
||||
}
|
||||
|
||||
void SetJSONInt(int &value, QJsonObject jsonDoc, const char *key) {
|
||||
if(jsonDoc.contains(key) && jsonDoc[key].isDouble())
|
||||
{
|
||||
value = (int)jsonDoc[key].toDouble();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ParseJSONStrings(QJsonObject jsonDoc, const char *key) {
|
||||
std::vector<std::string> values;
|
||||
if(jsonDoc.contains(key) && jsonDoc[key].isArray())
|
||||
{
|
||||
QJsonArray jsonArray = jsonDoc[key].toArray();
|
||||
foreach (const QJsonValue & value, jsonArray)
|
||||
{
|
||||
if (value.isString())
|
||||
{
|
||||
values.push_back(value.toString().toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
ImmichConfig ParseImmichConfigObject(QJsonObject immichJson) {
|
||||
ImmichConfig config;
|
||||
|
||||
std::string url = ParseJSONString(immichJson, "url");
|
||||
std::string apiKey = ParseJSONString(immichJson, "apiKey");
|
||||
if(!url.empty())
|
||||
config.url = url;
|
||||
if(!apiKey.empty())
|
||||
config.apiKey = apiKey;
|
||||
|
||||
std::string size = ParseJSONString(immichJson, "size");
|
||||
if(!size.empty())
|
||||
config.size = size;
|
||||
|
||||
std::string order = ParseJSONString(immichJson, "order");
|
||||
if(!order.empty())
|
||||
config.order = order;
|
||||
|
||||
std::string cachePath = ParseJSONString(immichJson, "cachePath");
|
||||
if(!cachePath.empty())
|
||||
config.cachePath = cachePath;
|
||||
|
||||
std::string albumId = ParseJSONString(immichJson, "albumId");
|
||||
if(!albumId.empty())
|
||||
config.albumIds.push_back(albumId);
|
||||
|
||||
std::vector<std::string> albumIds = ParseJSONStrings(immichJson, "albumIds");
|
||||
if(albumIds.size() > 0)
|
||||
config.albumIds = albumIds;
|
||||
|
||||
SetJSONInt(config.pageSize, immichJson, "pageSize");
|
||||
SetJSONInt(config.maxAssets, immichJson, "maxAssets");
|
||||
SetJSONInt(config.cacheMaxMB, immichJson, "cacheMaxMB");
|
||||
SetJSONBool(config.includeArchived, immichJson, "includeArchived");
|
||||
|
||||
if(!config.url.empty() && !config.apiKey.empty())
|
||||
config.enabled = true;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
MqttConfig ParseMqttConfigObject(QJsonObject mqttJson) {
|
||||
MqttConfig config;
|
||||
|
||||
std::string host = ParseJSONString(mqttJson, "host");
|
||||
if(!host.empty())
|
||||
config.host = host;
|
||||
|
||||
std::string topic = ParseJSONString(mqttJson, "topic");
|
||||
if(!topic.empty())
|
||||
config.topic = topic;
|
||||
|
||||
std::string clientId = ParseJSONString(mqttJson, "clientId");
|
||||
if(!clientId.empty())
|
||||
config.clientId = clientId;
|
||||
|
||||
std::string username = ParseJSONString(mqttJson, "username");
|
||||
if(!username.empty())
|
||||
config.username = username;
|
||||
|
||||
std::string password = ParseJSONString(mqttJson, "password");
|
||||
if(!password.empty())
|
||||
config.password = password;
|
||||
|
||||
SetJSONInt(config.port, mqttJson, "port");
|
||||
SetJSONInt(config.keepAlive, mqttJson, "keepAlive");
|
||||
SetJSONInt(config.qos, mqttJson, "qos");
|
||||
|
||||
if(!config.host.empty() && !config.topic.empty())
|
||||
config.enabled = true;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
Config loadConfiguration(const std::string &configFilePath, const Config ¤tConfig) {
|
||||
if(configFilePath.empty())
|
||||
{
|
||||
return currentConfig;
|
||||
}
|
||||
|
||||
QString jsonFile(configFilePath.c_str());
|
||||
QDir directory;
|
||||
if(!directory.exists(jsonFile))
|
||||
@@ -130,7 +232,7 @@ QString getAppConfigFilePath(const std::string &configPath) {
|
||||
std::string userConfigFolder = "~/.config/slide/";
|
||||
std::string systemConfigFolder = "/etc/slide";
|
||||
QString baseConfigFilename("slide.options.json");
|
||||
|
||||
|
||||
QDir directory(userConfigFolder.c_str());
|
||||
QString jsonFile = "";
|
||||
if (!configPath.empty())
|
||||
@@ -179,6 +281,11 @@ QVector<PathEntry> parsePathEntry(QJsonObject &jsonMainDoc, bool baseRecursive,
|
||||
|
||||
SetJSONBool(entry.baseDisplayOptions.fitAspectAxisToWindow, schedulerJson, "stretch");
|
||||
|
||||
if(schedulerJson.contains("immich") && schedulerJson["immich"].isObject())
|
||||
{
|
||||
entry.immich = ParseImmichConfigObject(schedulerJson["immich"].toObject());
|
||||
}
|
||||
|
||||
std::string pathString = ParseJSONString(schedulerJson, "path");
|
||||
if(!pathString.empty()) {
|
||||
entry.path = pathString;
|
||||
@@ -218,6 +325,11 @@ QVector<PathEntry> parsePathEntry(QJsonObject &jsonMainDoc, bool baseRecursive,
|
||||
}
|
||||
|
||||
AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) {
|
||||
if(commandLineConfig.configPath.empty())
|
||||
{
|
||||
return commandLineConfig;
|
||||
}
|
||||
|
||||
QString jsonFile = getAppConfigFilePath(commandLineConfig.configPath);
|
||||
QDir directory;
|
||||
if(!directory.exists(jsonFile))
|
||||
@@ -248,6 +360,11 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) {
|
||||
loadedConfig.overlay = overlayString;
|
||||
}
|
||||
|
||||
if(jsonDoc.contains("mqtt") && jsonDoc["mqtt"].isObject())
|
||||
{
|
||||
loadedConfig.mqtt = ParseMqttConfigObject(jsonDoc["mqtt"].toObject());
|
||||
}
|
||||
|
||||
loadedConfig.paths = parsePathEntry(jsonDoc, baseRecursive, baseShuffle, baseSorted);
|
||||
if(loadedConfig.paths.count() <= 0)
|
||||
{
|
||||
@@ -255,6 +372,10 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) {
|
||||
entry.recursive = baseRecursive;
|
||||
entry.sorted = baseSorted;
|
||||
entry.shuffle = baseShuffle;
|
||||
if(jsonDoc.contains("immich") && jsonDoc["immich"].isObject())
|
||||
{
|
||||
entry.immich = ParseImmichConfigObject(jsonDoc["immich"].toObject());
|
||||
}
|
||||
std::string pathString = ParseJSONString(jsonDoc, "path");
|
||||
if(!pathString.empty())
|
||||
{
|
||||
@@ -272,6 +393,10 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) {
|
||||
}
|
||||
|
||||
Config getConfigurationForFolder(const std::string &folderPath, const Config ¤tConfig) {
|
||||
if(folderPath.empty())
|
||||
{
|
||||
return currentConfig;
|
||||
}
|
||||
QDir directory(folderPath.c_str());
|
||||
QString jsonFile = directory.filePath(QString("options.json"));
|
||||
if(directory.exists(jsonFile))
|
||||
@@ -279,4 +404,4 @@ Config getConfigurationForFolder(const std::string &folderPath, const Config &cu
|
||||
return loadConfiguration(jsonFile.toStdString(), currentConfig );
|
||||
}
|
||||
return currentConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,86 @@
|
||||
#include <QDateTime>
|
||||
#include "imagestructs.h"
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
|
||||
struct ImmichConfig {
|
||||
bool enabled = false;
|
||||
std::string url = "";
|
||||
std::string apiKey = "";
|
||||
std::vector<std::string> albumIds;
|
||||
std::string size = "fullsize";
|
||||
std::string order = "desc";
|
||||
int pageSize = 200;
|
||||
int maxAssets = 1000;
|
||||
std::string cachePath = "";
|
||||
int cacheMaxMB = 512;
|
||||
bool includeArchived = false;
|
||||
|
||||
bool operator==(const ImmichConfig &b) const
|
||||
{
|
||||
if (enabled != b.enabled)
|
||||
return false;
|
||||
if (url != b.url || apiKey != b.apiKey)
|
||||
return false;
|
||||
if (size != b.size || order != b.order)
|
||||
return false;
|
||||
if (pageSize != b.pageSize || maxAssets != b.maxAssets)
|
||||
return false;
|
||||
if (cachePath != b.cachePath || cacheMaxMB != b.cacheMaxMB)
|
||||
return false;
|
||||
if (includeArchived != b.includeArchived)
|
||||
return false;
|
||||
if (albumIds.size() != b.albumIds.size())
|
||||
return false;
|
||||
for (size_t i = 0; i < albumIds.size(); ++i)
|
||||
{
|
||||
if (albumIds[i] != b.albumIds[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const ImmichConfig &b) const
|
||||
{
|
||||
return !operator==(b);
|
||||
}
|
||||
};
|
||||
|
||||
struct MqttConfig {
|
||||
bool enabled = false;
|
||||
std::string host = "localhost";
|
||||
int port = 1883;
|
||||
std::string topic = "slide/control";
|
||||
std::string clientId = "slide";
|
||||
std::string username = "";
|
||||
std::string password = "";
|
||||
int keepAlive = 30;
|
||||
int qos = 0;
|
||||
|
||||
bool operator==(const MqttConfig &b) const
|
||||
{
|
||||
return enabled == b.enabled &&
|
||||
host == b.host &&
|
||||
port == b.port &&
|
||||
topic == b.topic &&
|
||||
clientId == b.clientId &&
|
||||
username == b.username &&
|
||||
password == b.password &&
|
||||
keepAlive == b.keepAlive &&
|
||||
qos == b.qos;
|
||||
}
|
||||
|
||||
bool operator!=(const MqttConfig &b) const
|
||||
{
|
||||
return !operator==(b);
|
||||
}
|
||||
};
|
||||
|
||||
// configuration options that apply to an image/folder of images
|
||||
struct Config {
|
||||
public:
|
||||
unsigned int rotationSeconds = 30;
|
||||
unsigned int transitionTime = 1;
|
||||
int blurRadius = -1;
|
||||
int backgroundOpacity = -1;
|
||||
ImageDisplayOptions baseDisplayOptions;
|
||||
@@ -20,6 +95,7 @@ struct PathEntry {
|
||||
std::string imageList = "";
|
||||
bool exclusive = false; // only use this entry when it is valid, skip others
|
||||
|
||||
ImmichConfig immich;
|
||||
bool recursive = false;
|
||||
bool shuffle = false;
|
||||
bool sorted = false;
|
||||
@@ -39,6 +115,8 @@ struct PathEntry {
|
||||
return true;
|
||||
if (b.path != path || b.imageList != imageList)
|
||||
return true;
|
||||
if (b.immich != immich)
|
||||
return true;
|
||||
if (b.baseDisplayOptions.timeWindows.count() != baseDisplayOptions.timeWindows.count())
|
||||
return true;
|
||||
for(int i = 0; i < baseDisplayOptions.timeWindows.count(); ++i)
|
||||
@@ -58,6 +136,7 @@ struct AppConfig : public Config {
|
||||
std::string overlay = "";
|
||||
QString overlayHexRGB = "#FFFFFF";
|
||||
QVector<PathEntry> paths;
|
||||
MqttConfig mqtt;
|
||||
|
||||
bool debugMode = false;
|
||||
|
||||
@@ -82,4 +161,4 @@ Config getConfigurationForFolder(const std::string &folderPath, const Config &cu
|
||||
ImageAspectScreenFilter parseAspectFromString(char aspect);
|
||||
QString getAppConfigFilePath(const std::string &configPath);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -371,4 +371,4 @@ const ImageDetails ListImageSelector::getNextImage(const ImageDisplayOptions& ba
|
||||
}
|
||||
}
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ ImageSwitcher::ImageSwitcher(MainWindow& w, unsigned int timeoutMsec, std::uniqu
|
||||
|
||||
void ImageSwitcher::updateImage()
|
||||
{
|
||||
if (paused)
|
||||
return;
|
||||
if(reloadConfigIfNeeded)
|
||||
{
|
||||
reloadConfigIfNeeded(window, this);
|
||||
@@ -60,10 +62,64 @@ void ImageSwitcher::setConfigFileReloader(std::function<void(MainWindow &w, Imag
|
||||
void ImageSwitcher::setRotationTime(unsigned int timeoutMsecIn)
|
||||
{
|
||||
timeout = timeoutMsecIn;
|
||||
timer.start(timeout);
|
||||
if (!paused)
|
||||
timer.start(timeout);
|
||||
}
|
||||
|
||||
void ImageSwitcher::setImageSelector(std::unique_ptr<ImageSelector>& selectorIn)
|
||||
{
|
||||
selector = std::move(selectorIn);
|
||||
}
|
||||
|
||||
void ImageSwitcher::pause()
|
||||
{
|
||||
paused = true;
|
||||
timer.stop();
|
||||
timerNoContent.stop();
|
||||
}
|
||||
|
||||
void ImageSwitcher::resume()
|
||||
{
|
||||
if (!paused)
|
||||
return;
|
||||
paused = false;
|
||||
timer.start(timeout);
|
||||
scheduleImageUpdate();
|
||||
}
|
||||
|
||||
void ImageSwitcher::stepOnce()
|
||||
{
|
||||
bool wasPaused = paused;
|
||||
if (wasPaused)
|
||||
paused = false;
|
||||
updateImage();
|
||||
if (wasPaused)
|
||||
{
|
||||
paused = true;
|
||||
timer.stop();
|
||||
timerNoContent.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageSwitcher::restart(std::unique_ptr<ImageSelector>& selectorIn)
|
||||
{
|
||||
paused = false;
|
||||
timerNoContent.stop();
|
||||
setImageSelector(selectorIn);
|
||||
timer.start(timeout);
|
||||
scheduleImageUpdate();
|
||||
}
|
||||
|
||||
bool ImageSwitcher::skipToNextFolder()
|
||||
{
|
||||
auto *listSelector = dynamic_cast<ListImageSelector*>(selector.get());
|
||||
if (!listSelector)
|
||||
return false;
|
||||
stepOnce();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImageSwitcher::isPaused() const
|
||||
{
|
||||
return paused;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,12 @@ public:
|
||||
void setConfigFileReloader(std::function<void(MainWindow &w, ImageSwitcher *switcher)> reloadConfigIfNeededIn);
|
||||
void setRotationTime(unsigned int timeoutMsec);
|
||||
void setImageSelector(std::unique_ptr<ImageSelector>& selector);
|
||||
void pause();
|
||||
void resume();
|
||||
void stepOnce();
|
||||
void restart(std::unique_ptr<ImageSelector>& selector);
|
||||
bool skipToNextFolder();
|
||||
bool isPaused() const;
|
||||
|
||||
public slots:
|
||||
void updateImage();
|
||||
@@ -30,6 +36,7 @@ private:
|
||||
const unsigned int timeoutNoContent = 5 * 1000; // 5 sec
|
||||
QTimer timerNoContent;
|
||||
std::function<void(MainWindow &w, ImageSwitcher *switcher)> reloadConfigIfNeeded;
|
||||
bool paused = false;
|
||||
};
|
||||
|
||||
#endif // IMAGESWITCHER_H
|
||||
|
||||
337
src/immichclient.cpp
Normal file
337
src/immichclient.cpp
Normal file
@@ -0,0 +1,337 @@
|
||||
#include "immichclient.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QEventLoop>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QRegularExpression>
|
||||
#include <QSaveFile>
|
||||
#include <QTimer>
|
||||
#include <QUrlQuery>
|
||||
|
||||
namespace {
|
||||
const int kMetadataTimeoutMs = 15000;
|
||||
const int kAssetTimeoutMs = 30000;
|
||||
}
|
||||
|
||||
ImmichClient::ImmichClient(const ImmichConfig &configIn)
|
||||
: config(configIn)
|
||||
{}
|
||||
|
||||
QUrl ImmichClient::apiUrl(const QString &path) const
|
||||
{
|
||||
QString base = QString::fromStdString(config.url).trimmed();
|
||||
if (base.endsWith("/"))
|
||||
base.chop(1);
|
||||
if (!base.endsWith("/api"))
|
||||
base += "/api";
|
||||
return QUrl(base + path);
|
||||
}
|
||||
|
||||
QNetworkRequest ImmichClient::makeRequest(const QUrl &url) const
|
||||
{
|
||||
QNetworkRequest request(url);
|
||||
request.setRawHeader("x-api-key", QByteArray::fromStdString(config.apiKey));
|
||||
return request;
|
||||
}
|
||||
|
||||
bool ImmichClient::waitForReply(QNetworkReply *reply, QByteArray &data, QString *contentType, int timeoutMs)
|
||||
{
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
timer.start(timeoutMs);
|
||||
loop.exec();
|
||||
|
||||
if (!timer.isActive())
|
||||
{
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (contentType)
|
||||
*contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
|
||||
data = reply->readAll();
|
||||
bool ok = reply->error() == QNetworkReply::NoError;
|
||||
if (!ok)
|
||||
{
|
||||
Log("Immich request failed: ", reply->errorString().toStdString());
|
||||
}
|
||||
reply->deleteLater();
|
||||
return ok;
|
||||
}
|
||||
|
||||
QByteArray ImmichClient::postJson(const QUrl &url, const QJsonObject &body, QString *contentType, int timeoutMs)
|
||||
{
|
||||
QNetworkRequest request = makeRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
QNetworkReply *reply = manager.post(request, QJsonDocument(body).toJson(QJsonDocument::Compact));
|
||||
QByteArray data;
|
||||
if (!waitForReply(reply, data, contentType, timeoutMs))
|
||||
return QByteArray();
|
||||
return data;
|
||||
}
|
||||
|
||||
QByteArray ImmichClient::getBytes(const QUrl &url, QString *contentType, int timeoutMs)
|
||||
{
|
||||
QNetworkRequest request = makeRequest(url);
|
||||
request.setRawHeader("Accept", "*/*");
|
||||
QNetworkReply *reply = manager.get(request);
|
||||
QByteArray data;
|
||||
if (!waitForReply(reply, data, contentType, timeoutMs))
|
||||
return QByteArray();
|
||||
return data;
|
||||
}
|
||||
|
||||
QVector<ImmichAsset> ImmichClient::fetchAssets()
|
||||
{
|
||||
QVector<ImmichAsset> assets;
|
||||
if (!config.enabled)
|
||||
{
|
||||
Log("Immich config is missing url or apiKey.");
|
||||
return assets;
|
||||
}
|
||||
|
||||
int pageSize = config.pageSize > 0 ? config.pageSize : 200;
|
||||
int maxAssets = config.maxAssets;
|
||||
bool triedZero = false;
|
||||
int page = 1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
QJsonObject body;
|
||||
body["page"] = page;
|
||||
body["size"] = pageSize;
|
||||
body["type"] = "IMAGE";
|
||||
body["order"] = QString::fromStdString(config.order);
|
||||
if (config.includeArchived)
|
||||
body["withArchived"] = true;
|
||||
if (config.albumIds.size() > 0)
|
||||
{
|
||||
QJsonArray ids;
|
||||
for (const auto &id : config.albumIds)
|
||||
ids.append(QString::fromStdString(id));
|
||||
body["albumIds"] = ids;
|
||||
}
|
||||
|
||||
QByteArray response = postJson(apiUrl("/search/metadata"), body, nullptr, kMetadataTimeoutMs);
|
||||
if (response.isEmpty())
|
||||
break;
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(response);
|
||||
if (!doc.isObject())
|
||||
break;
|
||||
|
||||
QJsonObject root = doc.object();
|
||||
QJsonObject assetsObj = root["assets"].toObject();
|
||||
QJsonArray items = assetsObj["items"].toArray();
|
||||
int total = assetsObj["total"].toInt();
|
||||
if (items.isEmpty())
|
||||
{
|
||||
if (total > 0 && page == 1 && !triedZero)
|
||||
{
|
||||
triedZero = true;
|
||||
page = 0;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto &value : items)
|
||||
{
|
||||
QJsonObject item = value.toObject();
|
||||
QString id = item["id"].toString();
|
||||
if (id.isEmpty())
|
||||
continue;
|
||||
ImmichAsset asset;
|
||||
asset.id = id;
|
||||
asset.originalFileName = item["originalFileName"].toString();
|
||||
assets.append(asset);
|
||||
if (maxAssets > 0 && assets.size() >= maxAssets)
|
||||
return assets;
|
||||
}
|
||||
|
||||
if (items.size() < pageSize)
|
||||
break;
|
||||
page += 1;
|
||||
}
|
||||
|
||||
return assets;
|
||||
}
|
||||
|
||||
bool ImmichClient::downloadAsset(const QString &assetId, QByteArray &data, QString &contentType)
|
||||
{
|
||||
if (!config.enabled)
|
||||
return false;
|
||||
|
||||
QString size = QString::fromStdString(config.size).trimmed().toLower();
|
||||
if (size.isEmpty())
|
||||
size = "fullsize";
|
||||
|
||||
QUrl url;
|
||||
if (size == "original" || size == "download")
|
||||
{
|
||||
url = apiUrl("/assets/" + assetId + "/download");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size != "fullsize" && size != "preview" && size != "thumbnail")
|
||||
{
|
||||
Log("Immich size '", size.toStdString(), "' not recognized. Defaulting to fullsize.");
|
||||
size = "fullsize";
|
||||
}
|
||||
url = apiUrl("/assets/" + assetId + "/thumbnail");
|
||||
QUrlQuery query;
|
||||
query.addQueryItem("size", size);
|
||||
url.setQuery(query);
|
||||
}
|
||||
|
||||
QByteArray payload = getBytes(url, &contentType, kAssetTimeoutMs);
|
||||
if (payload.isEmpty())
|
||||
return false;
|
||||
|
||||
data = payload;
|
||||
return true;
|
||||
}
|
||||
|
||||
ImmichAssetCache::ImmichAssetCache(const ImmichConfig &config)
|
||||
{
|
||||
QString rawPath = QString::fromStdString(config.cachePath);
|
||||
cacheDirPath = resolveCachePath(rawPath);
|
||||
if (config.cacheMaxMB > 0)
|
||||
cacheMaxBytes = static_cast<qint64>(config.cacheMaxMB) * 1024 * 1024;
|
||||
}
|
||||
|
||||
QString ImmichAssetCache::resolveCachePath(const QString &rawPath) const
|
||||
{
|
||||
if (rawPath.isEmpty())
|
||||
{
|
||||
return QDir::homePath() + "/.cache/slide/immich";
|
||||
}
|
||||
if (rawPath.startsWith("~"))
|
||||
{
|
||||
return QDir::homePath() + rawPath.mid(1);
|
||||
}
|
||||
return rawPath;
|
||||
}
|
||||
|
||||
void ImmichAssetCache::ensureCacheDir() const
|
||||
{
|
||||
QDir dir(cacheDirPath);
|
||||
if (!dir.exists())
|
||||
dir.mkpath(".");
|
||||
}
|
||||
|
||||
QString ImmichAssetCache::findExisting(const QString &assetId) const
|
||||
{
|
||||
QDir dir(cacheDirPath);
|
||||
QStringList matches = dir.entryList(QStringList() << (assetId + "_*"), QDir::Files, QDir::Time);
|
||||
if (matches.isEmpty())
|
||||
return "";
|
||||
return dir.filePath(matches.first());
|
||||
}
|
||||
|
||||
QString ImmichAssetCache::sanitizeFileName(const QString &name) const
|
||||
{
|
||||
QString safe = name;
|
||||
safe.replace(QRegularExpression("[^A-Za-z0-9_.-]"), "_");
|
||||
if (safe.isEmpty())
|
||||
safe = "asset";
|
||||
return safe;
|
||||
}
|
||||
|
||||
QString ImmichAssetCache::extensionForContentType(const QString &contentType) const
|
||||
{
|
||||
if (contentType.contains("jpeg", Qt::CaseInsensitive))
|
||||
return "jpg";
|
||||
if (contentType.contains("png", Qt::CaseInsensitive))
|
||||
return "png";
|
||||
if (contentType.contains("webp", Qt::CaseInsensitive))
|
||||
return "webp";
|
||||
if (contentType.contains("gif", Qt::CaseInsensitive))
|
||||
return "gif";
|
||||
return "img";
|
||||
}
|
||||
|
||||
qint64 ImmichAssetCache::calculateCacheSize() const
|
||||
{
|
||||
QDir dir(cacheDirPath);
|
||||
QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Time);
|
||||
qint64 total = 0;
|
||||
for (const auto &info : files)
|
||||
total += info.size();
|
||||
return total;
|
||||
}
|
||||
|
||||
void ImmichAssetCache::enforceCacheLimit()
|
||||
{
|
||||
if (cacheMaxBytes <= 0)
|
||||
return;
|
||||
|
||||
QDir dir(cacheDirPath);
|
||||
QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Time);
|
||||
qint64 total = 0;
|
||||
for (const auto &info : files)
|
||||
total += info.size();
|
||||
|
||||
for (int i = files.size() - 1; i >= 0 && total > cacheMaxBytes; --i)
|
||||
{
|
||||
total -= files[i].size();
|
||||
QFile::remove(files[i].filePath());
|
||||
}
|
||||
cacheSizeBytes = total;
|
||||
cacheSizeKnown = true;
|
||||
}
|
||||
|
||||
QString ImmichAssetCache::getCachedPath(const QString &assetId, const QString &assetName, ImmichClient &client)
|
||||
{
|
||||
ensureCacheDir();
|
||||
|
||||
QString existing = findExisting(assetId);
|
||||
if (!existing.isEmpty())
|
||||
return existing;
|
||||
|
||||
QByteArray data;
|
||||
QString contentType;
|
||||
if (!client.downloadAsset(assetId, data, contentType))
|
||||
return "";
|
||||
|
||||
QString safeName = sanitizeFileName(assetName);
|
||||
QString extension = extensionForContentType(contentType);
|
||||
QString filename = assetId + "_" + safeName + "." + extension;
|
||||
|
||||
QDir dir(cacheDirPath);
|
||||
QString filePath = dir.filePath(filename);
|
||||
|
||||
QSaveFile file(filePath);
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
return "";
|
||||
file.write(data);
|
||||
if (!file.commit())
|
||||
return "";
|
||||
|
||||
if (cacheMaxBytes > 0)
|
||||
{
|
||||
if (!cacheSizeKnown)
|
||||
{
|
||||
cacheSizeBytes = calculateCacheSize();
|
||||
cacheSizeKnown = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheSizeBytes += data.size();
|
||||
}
|
||||
if (cacheSizeBytes > cacheMaxBytes)
|
||||
enforceCacheLimit();
|
||||
}
|
||||
|
||||
return filePath;
|
||||
}
|
||||
56
src/immichclient.h
Normal file
56
src/immichclient.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef IMMICHCLIENT_H
|
||||
#define IMMICHCLIENT_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QVector>
|
||||
|
||||
#include "appconfig.h"
|
||||
|
||||
struct ImmichAsset {
|
||||
QString id;
|
||||
QString originalFileName;
|
||||
};
|
||||
|
||||
class ImmichClient {
|
||||
public:
|
||||
explicit ImmichClient(const ImmichConfig &config);
|
||||
QVector<ImmichAsset> fetchAssets();
|
||||
bool downloadAsset(const QString &assetId, QByteArray &data, QString &contentType);
|
||||
|
||||
private:
|
||||
QUrl apiUrl(const QString &path) const;
|
||||
QNetworkRequest makeRequest(const QUrl &url) const;
|
||||
QByteArray postJson(const QUrl &url, const QJsonObject &body, QString *contentType, int timeoutMs);
|
||||
QByteArray getBytes(const QUrl &url, QString *contentType, int timeoutMs);
|
||||
bool waitForReply(QNetworkReply *reply, QByteArray &data, QString *contentType, int timeoutMs);
|
||||
|
||||
ImmichConfig config;
|
||||
QNetworkAccessManager manager;
|
||||
};
|
||||
|
||||
class ImmichAssetCache {
|
||||
public:
|
||||
explicit ImmichAssetCache(const ImmichConfig &config);
|
||||
QString getCachedPath(const QString &assetId, const QString &assetName, ImmichClient &client);
|
||||
|
||||
private:
|
||||
QString resolveCachePath(const QString &rawPath) const;
|
||||
QString findExisting(const QString &assetId) const;
|
||||
QString sanitizeFileName(const QString &name) const;
|
||||
QString extensionForContentType(const QString &contentType) const;
|
||||
void ensureCacheDir() const;
|
||||
void enforceCacheLimit();
|
||||
qint64 calculateCacheSize() const;
|
||||
|
||||
QString cacheDirPath;
|
||||
qint64 cacheMaxBytes = 0;
|
||||
bool cacheSizeKnown = false;
|
||||
qint64 cacheSizeBytes = 0;
|
||||
};
|
||||
|
||||
#endif // IMMICHCLIENT_H
|
||||
47
src/immichpathtraverser.cpp
Normal file
47
src/immichpathtraverser.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "immichpathtraverser.h"
|
||||
#include "logger.h"
|
||||
|
||||
ImmichPathTraverser::ImmichPathTraverser(const ImmichConfig &configIn)
|
||||
: PathTraverser(""),
|
||||
config(configIn),
|
||||
client(configIn),
|
||||
cache(configIn)
|
||||
{
|
||||
loadAssets();
|
||||
}
|
||||
|
||||
ImmichPathTraverser::~ImmichPathTraverser() {}
|
||||
|
||||
void ImmichPathTraverser::loadAssets()
|
||||
{
|
||||
assetIds.clear();
|
||||
assetNames.clear();
|
||||
QVector<ImmichAsset> assets = client.fetchAssets();
|
||||
for (const auto &asset : assets)
|
||||
{
|
||||
if (asset.id.isEmpty())
|
||||
continue;
|
||||
assetIds.append(asset.id);
|
||||
assetNames.insert(asset.id, asset.originalFileName);
|
||||
}
|
||||
Log("Immich assets loaded: ", assetIds.size());
|
||||
}
|
||||
|
||||
QStringList ImmichPathTraverser::getImages() const
|
||||
{
|
||||
return assetIds;
|
||||
}
|
||||
|
||||
const std::string ImmichPathTraverser::getImagePath(const std::string image) const
|
||||
{
|
||||
QString assetId = QString::fromStdString(image);
|
||||
QString name = assetNames.value(assetId);
|
||||
QString path = cache.getCachedPath(assetId, name, client);
|
||||
return path.toStdString();
|
||||
}
|
||||
|
||||
ImageDisplayOptions ImmichPathTraverser::UpdateOptionsForImage(const std::string& filename, const ImageDisplayOptions& options) const
|
||||
{
|
||||
Q_UNUSED(filename);
|
||||
return options;
|
||||
}
|
||||
28
src/immichpathtraverser.h
Normal file
28
src/immichpathtraverser.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef IMMICHPATHTRAVERSER_H
|
||||
#define IMMICHPATHTRAVERSER_H
|
||||
|
||||
#include "pathtraverser.h"
|
||||
#include "immichclient.h"
|
||||
|
||||
#include <QHash>
|
||||
|
||||
class ImmichPathTraverser : public PathTraverser
|
||||
{
|
||||
public:
|
||||
ImmichPathTraverser(const ImmichConfig &config);
|
||||
virtual ~ImmichPathTraverser();
|
||||
QStringList getImages() const override;
|
||||
virtual const std::string getImagePath(const std::string image) const override;
|
||||
virtual ImageDisplayOptions UpdateOptionsForImage(const std::string& filename, const ImageDisplayOptions& options) const override;
|
||||
|
||||
private:
|
||||
void loadAssets();
|
||||
|
||||
ImmichConfig config;
|
||||
mutable ImmichClient client;
|
||||
mutable ImmichAssetCache cache;
|
||||
QStringList assetIds;
|
||||
QHash<QString, QString> assetNames;
|
||||
};
|
||||
|
||||
#endif // IMMICHPATHTRAVERSER_H
|
||||
44
src/main.cpp
44
src/main.cpp
@@ -2,12 +2,13 @@
|
||||
#include "imageselector.h"
|
||||
#include "imageswitcher.h"
|
||||
#include "pathtraverser.h"
|
||||
#include "immichpathtraverser.h"
|
||||
#include "mqttcontroller.h"
|
||||
#include "overlay.h"
|
||||
#include "appconfig.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QRegularExpression>
|
||||
#include <iostream>
|
||||
#include <sys/file.h>
|
||||
@@ -20,7 +21,7 @@
|
||||
#include <memory>
|
||||
|
||||
void usage(std::string programName) {
|
||||
std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-a aspect('l','p','a', 'm')] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder [-r] [-s] [-v] [--verbose] [--stretch] [-c config_file_path]" << std::endl;
|
||||
std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-T transition_seconds] [-h/--overlay-color #rrggbb] [-a aspect('l','p','a', 'm')] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder [-r] [-s] [-S] [-v] [--verbose] [--stretch] [-c config_file_path]" << std::endl;
|
||||
}
|
||||
|
||||
bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) {
|
||||
@@ -34,7 +35,7 @@ bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) {
|
||||
{"overlay-color", required_argument, 0, 'h'},
|
||||
};
|
||||
int option_index = 0;
|
||||
while ((opt = getopt_long(argc, argv, "b:p:t:o:O:a:i:c:h:rsSv", long_options, &option_index)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv, "b:p:t:T:o:O:a:i:c:h:rsSv", long_options, &option_index)) != -1) {
|
||||
switch (opt) {
|
||||
case 0:
|
||||
/* If this option set a flag, do nothing else now. */
|
||||
@@ -61,6 +62,9 @@ bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) {
|
||||
case 't':
|
||||
appConfig.rotationSeconds = atoi(optarg);
|
||||
break;
|
||||
case 'T':
|
||||
appConfig.transitionTime =atoi(optarg);
|
||||
break;
|
||||
case 'b':
|
||||
appConfig.blurRadius = atoi(optarg);
|
||||
break;
|
||||
@@ -129,6 +133,8 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig)
|
||||
w.setBackgroundOpacity(appConfig.backgroundOpacity);
|
||||
}
|
||||
|
||||
w.setTransitionTime(appConfig.transitionTime);
|
||||
|
||||
if (!appConfig.overlayHexRGB.isEmpty())
|
||||
{
|
||||
QRegularExpression hexRGBMatcher("^#([0-9A-Fa-f]{3}){1,2}$");
|
||||
@@ -153,7 +159,11 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig)
|
||||
std::unique_ptr<ImageSelector> GetSelectorForConfig(const PathEntry& path)
|
||||
{
|
||||
std::unique_ptr<PathTraverser> pathTraverser;
|
||||
if (!path.imageList.empty())
|
||||
if (path.immich.enabled)
|
||||
{
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new ImmichPathTraverser(path.immich));
|
||||
}
|
||||
else if (!path.imageList.empty())
|
||||
{
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(path.imageList));
|
||||
}
|
||||
@@ -205,6 +215,11 @@ std::unique_ptr<ImageSelector> GetSelectorForApp(const AppConfig& appConfig)
|
||||
|
||||
void ReloadConfigIfNeeded(AppConfig &appConfig, MainWindow &w, ImageSwitcher *switcher)
|
||||
{
|
||||
if(appConfig.configPath.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString jsonFile = getAppConfigFilePath(appConfig.configPath);
|
||||
QDir directory;
|
||||
if(!directory.exists(jsonFile))
|
||||
@@ -251,11 +266,8 @@ int main(int argc, char *argv[])
|
||||
Log( "Rotation Time: ", appConfig.rotationSeconds );
|
||||
Log( "Overlay input: ", appConfig.overlay );
|
||||
|
||||
QNetworkAccessManager webCtrl;
|
||||
|
||||
MainWindow w;
|
||||
ConfigureWindowFromSettings(w, appConfig);
|
||||
w.setNetworkManager(&webCtrl);
|
||||
w.show();
|
||||
|
||||
std::unique_ptr<ImageSelector> selector = GetSelectorForApp(appConfig);
|
||||
@@ -264,6 +276,24 @@ int main(int argc, char *argv[])
|
||||
w.setImageSwitcher(&switcher);
|
||||
std::function<void(MainWindow &w, ImageSwitcher *switcher)> reloader = [&appConfig](MainWindow &w, ImageSwitcher *switcher) { ReloadConfigIfNeeded(appConfig, w, switcher); };
|
||||
switcher.setConfigFileReloader(reloader);
|
||||
|
||||
std::unique_ptr<MqttController> mqttController;
|
||||
if (appConfig.mqtt.enabled)
|
||||
{
|
||||
mqttController = std::unique_ptr<MqttController>(new MqttController(appConfig.mqtt, &a));
|
||||
QObject::connect(mqttController.get(), &MqttController::play, [&switcher]() { switcher.resume(); });
|
||||
QObject::connect(mqttController.get(), &MqttController::pause, [&switcher]() { switcher.pause(); });
|
||||
QObject::connect(mqttController.get(), &MqttController::nextImage, [&switcher]() { switcher.stepOnce(); });
|
||||
QObject::connect(mqttController.get(), &MqttController::nextFolder, [&switcher]() {
|
||||
if (!switcher.skipToNextFolder())
|
||||
switcher.stepOnce();
|
||||
});
|
||||
QObject::connect(mqttController.get(), &MqttController::restart, [&appConfig, &switcher]() {
|
||||
std::unique_ptr<ImageSelector> newSelector = GetSelectorForApp(appConfig);
|
||||
switcher.restart(newSelector);
|
||||
});
|
||||
mqttController->start();
|
||||
}
|
||||
switcher.start();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QNetworkReply>
|
||||
#include <sstream>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
@@ -119,8 +117,9 @@ bool MainWindow::event(QEvent* event)
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QMainWindow::resizeEvent(event);
|
||||
updateImage(true);
|
||||
QMainWindow::resizeEvent(event);
|
||||
this->findChild<QLabel*>("image")->clear();
|
||||
updateImage();
|
||||
}
|
||||
|
||||
void MainWindow::checkWindowSize()
|
||||
@@ -133,7 +132,7 @@ void MainWindow::checkWindowSize()
|
||||
{
|
||||
Log("Resizing Window", screenSize.width(), "," , screenSize.height() );
|
||||
setFixedSize(screenSize);
|
||||
updateImage(true);
|
||||
updateImage();
|
||||
}
|
||||
|
||||
if (imageAspectMatchesMonitor)
|
||||
@@ -161,49 +160,18 @@ void MainWindow::checkWindowSize()
|
||||
void MainWindow::setImage(const ImageDetails &imageDetails)
|
||||
{
|
||||
currentImage = imageDetails;
|
||||
downloadedData.clear();
|
||||
if (pendingReply)
|
||||
{
|
||||
pendingReply->abort();
|
||||
}
|
||||
updateImage(false);
|
||||
updateImage();
|
||||
}
|
||||
|
||||
void MainWindow::fileDownloaded(QNetworkReply* netReply)
|
||||
{
|
||||
if (netReply == pendingReply)
|
||||
{
|
||||
pendingReply = nullptr;
|
||||
QNetworkReply::NetworkError err = netReply->error();
|
||||
if (err == QNetworkReply::NoError)
|
||||
{
|
||||
downloadedData = netReply->readAll();
|
||||
netReply->deleteLater();
|
||||
updateImage(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateImage(bool immediately)
|
||||
void MainWindow::updateImage()
|
||||
{
|
||||
checkWindowSize();
|
||||
if (currentImage.filename == "")
|
||||
return;
|
||||
|
||||
if (currentImage.filename.find("https://") != std::string::npos && downloadedData.isNull())
|
||||
{
|
||||
if (pendingReply == nullptr)
|
||||
{
|
||||
QNetworkRequest request(QUrl(currentImage.filename.c_str()));
|
||||
pendingReply = networkManager->get(request);
|
||||
connect( networkManager, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
QLabel *label = this->findChild<QLabel*>("image");
|
||||
const QPixmap* oldImage = label->pixmap();
|
||||
if (oldImage != NULL && !immediately)
|
||||
if (oldImage != NULL && transitionSeconds > 0)
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setBrush(QPalette::Background, *oldImage);
|
||||
@@ -211,18 +179,7 @@ void MainWindow::updateImage(bool immediately)
|
||||
}
|
||||
|
||||
QPixmap p;
|
||||
if (!downloadedData.isNull())
|
||||
{
|
||||
p.loadFromData(downloadedData);
|
||||
// BUG BUG have the selector update this?
|
||||
currentImage.width = p.width();
|
||||
currentImage.height = p.height();
|
||||
currentImage.rotation = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.load( currentImage.filename.c_str() );
|
||||
}
|
||||
p.load( currentImage.filename.c_str() );
|
||||
|
||||
Log("size:", p.width(), "x", p.height(), "(window:", width(), ",", height(), ")");
|
||||
|
||||
@@ -256,13 +213,13 @@ void MainWindow::updateImage(bool immediately)
|
||||
|
||||
label->setPixmap(background);
|
||||
|
||||
if (oldImage != NULL && !immediately)
|
||||
if (oldImage != NULL && transitionSeconds > 0)
|
||||
{
|
||||
auto effect = new QGraphicsOpacityEffect(label);
|
||||
effect->setOpacity(0.0);
|
||||
label->setGraphicsEffect(effect);
|
||||
QPropertyAnimation* animation = new QPropertyAnimation(effect, "opacity");
|
||||
animation->setDuration(1000);
|
||||
animation->setDuration(transitionSeconds*1000);
|
||||
animation->setStartValue(0);
|
||||
animation->setEndValue(1);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
@@ -298,8 +255,10 @@ void MainWindow::setOverlay(std::unique_ptr<Overlay> &o)
|
||||
QPixmap MainWindow::getBlurredBackground(const QPixmap& originalSize, const QPixmap& scaled)
|
||||
{
|
||||
if (currentImage.options.fitAspectAxisToWindow) {
|
||||
// our scaled version will just fill the whole screen, us it directly
|
||||
return scaled.copy();
|
||||
// our scaled version will just fill the whole screen, use it directly
|
||||
//Log("Using scaled image");
|
||||
QRect rect((scaled.width() - width())/2, 0, width(), height());
|
||||
return scaled.copy(rect);
|
||||
} else if (scaled.width() < width()) {
|
||||
QPixmap background = blur(originalSize.scaledToWidth(width(), Qt::SmoothTransformation));
|
||||
QRect rect(0, (background.height() - height())/2, width(), height());
|
||||
@@ -323,18 +282,32 @@ QPixmap MainWindow::getScaledPixmap(const QPixmap& p)
|
||||
{
|
||||
if (currentImage.options.fitAspectAxisToWindow)
|
||||
{
|
||||
if (currentImage.aspect() == ImageAspect_Portrait)
|
||||
bool stretchWidth = currentImage.aspect() == ImageAspect_Landscape;
|
||||
bool stretchHeight = currentImage.aspect() == ImageAspect_Portrait;
|
||||
// check the stretched image will naturally fill the screen for its aspect ratio
|
||||
if (stretchHeight && (width() > ((double)height()/p.height())*p.width()))
|
||||
{
|
||||
// stretched via height won't fill the width, so stretch the other way
|
||||
stretchHeight = false;
|
||||
stretchWidth = true;
|
||||
}
|
||||
else if (stretchWidth && (height() > ((double)width()/p.width())*p.height()))
|
||||
{
|
||||
// stretched via width won't fill the width, so stretch the other way
|
||||
stretchWidth = false;
|
||||
stretchHeight = true;
|
||||
}
|
||||
|
||||
if (stretchHeight)
|
||||
{
|
||||
// potrait mode, make height of image fit screen and crop top/bottom
|
||||
QPixmap pTemp = p.scaledToHeight(height(), Qt::SmoothTransformation);
|
||||
return pTemp.copy(0,0,width(),height());
|
||||
}
|
||||
else if (currentImage.aspect() == ImageAspect_Landscape)
|
||||
else if (stretchWidth)
|
||||
{
|
||||
// landscape mode, make width of image fit screen and crop top/bottom
|
||||
QPixmap pTemp = p.scaledToWidth(width(), Qt::SmoothTransformation);
|
||||
//int imageTempWidth = pTemp.width();
|
||||
//int imageTempHeight = pTemp.height();
|
||||
return pTemp.copy(0,0,width(),height());
|
||||
}
|
||||
}
|
||||
@@ -393,6 +366,11 @@ void MainWindow::setOverlayHexRGB(QString overlayHexRGB)
|
||||
this->overlayHexRGB = overlayHexRGB;
|
||||
}
|
||||
|
||||
void MainWindow::setTransitionTime(unsigned int transitionSeconds)
|
||||
{
|
||||
this->transitionSeconds = transitionSeconds;
|
||||
}
|
||||
|
||||
void MainWindow::warn(std::string text)
|
||||
{
|
||||
QLabel *label = this->findChild<QLabel*>("image");
|
||||
@@ -418,8 +396,3 @@ const ImageDisplayOptions &MainWindow::getBaseOptions()
|
||||
{
|
||||
return baseImageOptions;
|
||||
}
|
||||
|
||||
void MainWindow::setNetworkManager(QNetworkAccessManager *networkManagerIn)
|
||||
{
|
||||
networkManager = networkManagerIn;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QPixmap>
|
||||
#include <QNetworkAccessManager>
|
||||
#include "imagestructs.h"
|
||||
#include "imageselector.h"
|
||||
|
||||
@@ -28,17 +27,15 @@ public:
|
||||
void setImage(const ImageDetails &imageDetails);
|
||||
void setBlurRadius(unsigned int blurRadius);
|
||||
void setBackgroundOpacity(unsigned int opacity);
|
||||
void setTransitionTime(unsigned int transitionSeconds);
|
||||
void warn(std::string text);
|
||||
void setOverlay(std::unique_ptr<Overlay> &overlay);
|
||||
void setBaseOptions(const ImageDisplayOptions &baseOptionsIn);
|
||||
const ImageDisplayOptions &getBaseOptions();
|
||||
void setImageSwitcher(ImageSwitcher *switcherIn);
|
||||
void setNetworkManager(QNetworkAccessManager *networkManagerIn);
|
||||
void setOverlayHexRGB(QString overlayHexRGB);
|
||||
public slots:
|
||||
void checkWindowSize();
|
||||
private slots:
|
||||
void fileDownloaded(QNetworkReply* pReply);
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
@@ -47,18 +44,16 @@ private:
|
||||
ImageDisplayOptions baseImageOptions;
|
||||
bool imageAspectMatchesMonitor = false;
|
||||
ImageDetails currentImage;
|
||||
QByteArray downloadedData;
|
||||
QNetworkAccessManager *networkManager = nullptr;
|
||||
QNetworkReply *pendingReply = nullptr;
|
||||
QSize lastScreenSize = {0,0};
|
||||
QString overlayHexRGB = "#FFFF";
|
||||
unsigned int transitionSeconds = 1;
|
||||
|
||||
std::unique_ptr<Overlay> overlay;
|
||||
ImageSwitcher *switcher = nullptr;
|
||||
|
||||
void drawText(QPixmap& image, int margin, int fontsize, QString text, int alignment);
|
||||
|
||||
void updateImage(bool immediately);
|
||||
void updateImage();
|
||||
int getImageRotation();
|
||||
|
||||
QPixmap getBlurredBackground(const QPixmap& originalSize, const QPixmap& scaled);
|
||||
|
||||
152
src/mqttcontroller.cpp
Normal file
152
src/mqttcontroller.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
#include "mqttcontroller.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <QMetaObject>
|
||||
|
||||
#include <mosquitto.h>
|
||||
|
||||
namespace {
|
||||
bool g_mqttInitialized = false;
|
||||
}
|
||||
|
||||
MqttController::MqttController(const MqttConfig &configIn, QObject *parent)
|
||||
: QObject(parent),
|
||||
config(configIn)
|
||||
{
|
||||
if (!g_mqttInitialized)
|
||||
{
|
||||
mosquitto_lib_init();
|
||||
g_mqttInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
MqttController::~MqttController()
|
||||
{
|
||||
if (client)
|
||||
{
|
||||
mosquitto_disconnect(client);
|
||||
mosquitto_loop_stop(client, true);
|
||||
mosquitto_destroy(client);
|
||||
client = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MqttController::start()
|
||||
{
|
||||
if (!config.enabled)
|
||||
{
|
||||
Log("MQTT disabled or missing host/topic.");
|
||||
return;
|
||||
}
|
||||
|
||||
QString clientId = QString::fromStdString(config.clientId);
|
||||
if (clientId.isEmpty())
|
||||
clientId = "slide";
|
||||
|
||||
client = mosquitto_new(clientId.toUtf8().constData(), true, this);
|
||||
if (!client)
|
||||
{
|
||||
Log("MQTT: failed to create client.");
|
||||
return;
|
||||
}
|
||||
|
||||
mosquitto_connect_callback_set(client, &MqttController::HandleConnect);
|
||||
mosquitto_message_callback_set(client, &MqttController::HandleMessage);
|
||||
|
||||
if (!config.username.empty())
|
||||
{
|
||||
mosquitto_username_pw_set(client, config.username.c_str(),
|
||||
config.password.empty() ? nullptr : config.password.c_str());
|
||||
}
|
||||
|
||||
mosquitto_reconnect_delay_set(client, 2, 30, true);
|
||||
|
||||
int rc = mosquitto_connect_async(client, config.host.c_str(), config.port, config.keepAlive);
|
||||
if (rc != MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
Log("MQTT connect failed: ", mosquitto_strerror(rc));
|
||||
return;
|
||||
}
|
||||
|
||||
rc = mosquitto_loop_start(client);
|
||||
if (rc != MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
Log("MQTT loop start failed: ", mosquitto_strerror(rc));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MqttController::HandleConnect(struct mosquitto *mosq, void *userdata, int rc)
|
||||
{
|
||||
auto *self = static_cast<MqttController *>(userdata);
|
||||
if (!self || !mosq)
|
||||
return;
|
||||
if (rc != 0)
|
||||
{
|
||||
Log("MQTT connect error: ", mosquitto_strerror(rc));
|
||||
return;
|
||||
}
|
||||
self->connected = true;
|
||||
self->subscribe();
|
||||
}
|
||||
|
||||
void MqttController::subscribe()
|
||||
{
|
||||
if (!client || !connected)
|
||||
return;
|
||||
int rc = mosquitto_subscribe(client, nullptr, config.topic.c_str(), config.qos);
|
||||
if (rc != MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
Log("MQTT subscribe failed: ", mosquitto_strerror(rc));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("MQTT subscribed to ", config.topic);
|
||||
}
|
||||
}
|
||||
|
||||
void MqttController::HandleMessage(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
|
||||
{
|
||||
Q_UNUSED(mosq);
|
||||
auto *self = static_cast<MqttController *>(userdata);
|
||||
if (!self || !message || !message->payload)
|
||||
return;
|
||||
|
||||
QString payload = QString::fromUtf8(static_cast<const char *>(message->payload), message->payloadlen);
|
||||
QMetaObject::invokeMethod(self, "handleCommand", Qt::QueuedConnection, Q_ARG(QString, payload));
|
||||
}
|
||||
|
||||
void MqttController::handleCommand(const QString &payload)
|
||||
{
|
||||
QString cmd = payload.trimmed().toLower();
|
||||
if (cmd.isEmpty())
|
||||
return;
|
||||
|
||||
if (cmd == "play" || cmd == "resume")
|
||||
{
|
||||
emit play();
|
||||
return;
|
||||
}
|
||||
if (cmd == "pause")
|
||||
{
|
||||
emit pause();
|
||||
return;
|
||||
}
|
||||
if (cmd == "next" || cmd == "skip" || cmd == "next-image")
|
||||
{
|
||||
emit nextImage();
|
||||
return;
|
||||
}
|
||||
if (cmd == "next-folder" || cmd == "folder-next" || cmd == "skip-folder")
|
||||
{
|
||||
emit nextFolder();
|
||||
return;
|
||||
}
|
||||
if (cmd == "restart" || cmd == "reset")
|
||||
{
|
||||
emit restart();
|
||||
return;
|
||||
}
|
||||
|
||||
Log("MQTT unknown command: ", cmd.toStdString());
|
||||
}
|
||||
42
src/mqttcontroller.h
Normal file
42
src/mqttcontroller.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef MQTTCONTROLLER_H
|
||||
#define MQTTCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "appconfig.h"
|
||||
|
||||
struct mosquitto;
|
||||
struct mosquitto_message;
|
||||
|
||||
class MqttController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MqttController(const MqttConfig &config, QObject *parent = nullptr);
|
||||
~MqttController();
|
||||
|
||||
void start();
|
||||
|
||||
signals:
|
||||
void play();
|
||||
void pause();
|
||||
void nextImage();
|
||||
void nextFolder();
|
||||
void restart();
|
||||
|
||||
private slots:
|
||||
void handleCommand(const QString &payload);
|
||||
|
||||
private:
|
||||
static void HandleConnect(struct mosquitto *mosq, void *userdata, int rc);
|
||||
static void HandleMessage(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message);
|
||||
|
||||
void subscribe();
|
||||
|
||||
MqttConfig config;
|
||||
struct mosquitto *client = nullptr;
|
||||
bool connected = false;
|
||||
};
|
||||
|
||||
#endif // MQTTCONTROLLER_H
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <QDirIterator>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QDomDocument>
|
||||
#include <QDomAttr>
|
||||
#include <iostream>
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
#include <iostream>
|
||||
#include <QDir>
|
||||
#include <QStringList>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include "imageselector.h"
|
||||
|
||||
static const QStringList supportedFormats={"jpg","jpeg","png","tif","tiff"};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network xml
|
||||
QT += core gui network
|
||||
CONFIG += qt
|
||||
CONFIG += debug
|
||||
CONFIG += c++1z
|
||||
@@ -35,6 +35,9 @@ SOURCES += \
|
||||
mainwindow.cpp \
|
||||
imageswitcher.cpp \
|
||||
pathtraverser.cpp \
|
||||
immichpathtraverser.cpp \
|
||||
immichclient.cpp \
|
||||
mqttcontroller.cpp \
|
||||
overlay.cpp \
|
||||
imageselector.cpp \
|
||||
appconfig.cpp \
|
||||
@@ -45,6 +48,9 @@ HEADERS += \
|
||||
mainwindow.h \
|
||||
imageselector.h \
|
||||
pathtraverser.h \
|
||||
immichpathtraverser.h \
|
||||
immichclient.h \
|
||||
mqttcontroller.h \
|
||||
overlay.h \
|
||||
imageswitcher.h \
|
||||
imagestructs.h \
|
||||
@@ -58,3 +64,4 @@ target.path = /usr/local/bin/
|
||||
INSTALLS += target
|
||||
|
||||
unix|win32: LIBS += -lexif
|
||||
unix|win32: LIBS += -lmosquitto
|
||||
|
||||
Reference in New Issue
Block a user