2021-04-29 13:28:18 +00:00
|
|
|
from owrx.controllers.settings import SettingsFormController
|
|
|
|
from owrx.form.section import Section
|
2021-02-11 18:31:44 +00:00
|
|
|
from owrx.config.core import CoreConfig
|
2021-04-29 13:17:21 +00:00
|
|
|
from owrx.form.input import (
|
2020-03-29 18:14:34 +00:00
|
|
|
TextInput,
|
|
|
|
NumberInput,
|
|
|
|
FloatInput,
|
|
|
|
TextAreaInput,
|
|
|
|
DropdownInput,
|
|
|
|
Option,
|
|
|
|
)
|
2021-04-29 13:17:21 +00:00
|
|
|
from owrx.form.input.converter import WaterfallColorsConverter, IntConverter
|
|
|
|
from owrx.form.input.receiverid import ReceiverKeysConverter
|
|
|
|
from owrx.form.input.gfx import AvatarInput, TopPhotoInput
|
|
|
|
from owrx.form.input.device import WaterfallLevelsInput, WaterfallAutoLevelsInput
|
2021-09-30 21:26:26 +00:00
|
|
|
from owrx.form.input.location import LocationInput
|
2021-02-16 16:12:57 +00:00
|
|
|
from owrx.waterfall import WaterfallOptions
|
2021-04-18 15:49:13 +00:00
|
|
|
from owrx.breadcrumb import Breadcrumb, BreadcrumbItem
|
|
|
|
from owrx.controllers.settings import SettingsBreadcrumb
|
2021-02-08 22:36:46 +00:00
|
|
|
import shutil
|
2021-02-10 20:29:46 +00:00
|
|
|
import os
|
2021-05-07 14:57:54 +00:00
|
|
|
import re
|
2021-02-10 21:24:43 +00:00
|
|
|
from glob import glob
|
2020-03-26 22:04:02 +00:00
|
|
|
|
2021-02-15 14:29:02 +00:00
|
|
|
import logging
|
2020-04-26 00:15:19 +00:00
|
|
|
|
2021-02-15 14:29:02 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2020-04-25 19:55:52 +00:00
|
|
|
|
|
|
|
|
2021-02-15 14:40:37 +00:00
|
|
|
class GeneralSettingsController(SettingsFormController):
|
|
|
|
def getTitle(self):
|
|
|
|
return "General Settings"
|
2020-03-26 20:52:34 +00:00
|
|
|
|
2021-04-18 15:49:13 +00:00
|
|
|
def get_breadcrumb(self) -> Breadcrumb:
|
|
|
|
return SettingsBreadcrumb().append(BreadcrumbItem("General Settings", "settings/general"))
|
|
|
|
|
2021-02-15 14:40:37 +00:00
|
|
|
def getSections(self):
|
|
|
|
return [
|
|
|
|
Section(
|
|
|
|
"Receiver information",
|
|
|
|
TextInput("receiver_name", "Receiver name"),
|
|
|
|
TextInput("receiver_location", "Receiver location"),
|
|
|
|
NumberInput(
|
|
|
|
"receiver_asl",
|
|
|
|
"Receiver elevation",
|
|
|
|
append="meters above mean sea level",
|
|
|
|
),
|
|
|
|
TextInput("receiver_admin", "Receiver admin"),
|
|
|
|
LocationInput("receiver_gps", "Receiver coordinates"),
|
|
|
|
TextInput("photo_title", "Photo title"),
|
|
|
|
TextAreaInput("photo_desc", "Photo description"),
|
|
|
|
),
|
|
|
|
Section(
|
|
|
|
"Receiver images",
|
|
|
|
AvatarInput(
|
|
|
|
"receiver_avatar",
|
|
|
|
"Receiver Avatar",
|
|
|
|
infotext="For performance reasons, images are cached. "
|
|
|
|
+ "It can take a few hours until they appear on the site.",
|
|
|
|
),
|
|
|
|
TopPhotoInput(
|
|
|
|
"receiver_top_photo",
|
|
|
|
"Receiver Panorama",
|
|
|
|
infotext="For performance reasons, images are cached. "
|
|
|
|
+ "It can take a few hours until they appear on the site.",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Section(
|
|
|
|
"Receiver limits",
|
|
|
|
NumberInput(
|
|
|
|
"max_clients",
|
|
|
|
"Maximum number of clients",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Section(
|
|
|
|
"Receiver listings",
|
|
|
|
TextAreaInput(
|
|
|
|
"receiver_keys",
|
|
|
|
"Receiver keys",
|
|
|
|
converter=ReceiverKeysConverter(),
|
|
|
|
infotext="Put the keys you receive on listing sites (e.g. "
|
2021-02-15 19:20:32 +00:00
|
|
|
+ '<a href="https://www.receiverbook.de" target="_blank">Receiverbook</a>) here, one per line',
|
2021-02-15 14:40:37 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Section(
|
|
|
|
"Waterfall settings",
|
2021-02-16 16:12:57 +00:00
|
|
|
DropdownInput(
|
|
|
|
"waterfall_scheme",
|
|
|
|
"Waterfall color scheme",
|
|
|
|
options=WaterfallOptions,
|
|
|
|
),
|
2021-02-16 17:07:13 +00:00
|
|
|
TextAreaInput(
|
|
|
|
"waterfall_colors",
|
|
|
|
"Custom waterfall colors",
|
2021-02-16 17:39:42 +00:00
|
|
|
infotext="Please provide 6-digit hexadecimal RGB colors in HTML notation (#RRGGBB)"
|
|
|
|
+ " or HEX notation (0xRRGGBB), one per line",
|
|
|
|
converter=WaterfallColorsConverter(),
|
2021-02-16 17:07:13 +00:00
|
|
|
),
|
2021-02-15 14:40:37 +00:00
|
|
|
NumberInput(
|
|
|
|
"fft_fps",
|
|
|
|
"FFT speed",
|
|
|
|
infotext="This setting specifies how many lines are being added to the waterfall per second. "
|
|
|
|
+ "Higher values will give you a faster waterfall, but will also use more CPU.",
|
|
|
|
append="frames per second",
|
|
|
|
),
|
|
|
|
NumberInput("fft_size", "FFT size", append="bins"),
|
|
|
|
FloatInput(
|
|
|
|
"fft_voverlap_factor",
|
|
|
|
"FFT vertical overlap factor",
|
|
|
|
infotext="If fft_voverlap_factor is above 0, multiple FFTs will be used for creating a line on the "
|
|
|
|
+ "diagram.",
|
|
|
|
),
|
2021-02-25 14:13:39 +00:00
|
|
|
WaterfallLevelsInput("waterfall_levels", "Waterfall levels"),
|
2021-03-30 22:18:06 +00:00
|
|
|
WaterfallAutoLevelsInput(
|
|
|
|
"waterfall_auto_levels",
|
|
|
|
"Automatic adjustment margins",
|
|
|
|
infotext="Specifies the upper and lower dynamic headroom that should be added when automatically "
|
|
|
|
+ "adjusting waterfall colors",
|
|
|
|
),
|
|
|
|
NumberInput(
|
|
|
|
"waterfall_auto_min_range",
|
|
|
|
"Automatic adjustment minimum range",
|
|
|
|
append="dB",
|
|
|
|
infotext="Minimum dynamic range the waterfall should cover after automatically adjusting "
|
|
|
|
+ "waterfall colors",
|
|
|
|
),
|
2021-02-15 14:40:37 +00:00
|
|
|
),
|
|
|
|
Section(
|
|
|
|
"Compression",
|
|
|
|
DropdownInput(
|
|
|
|
"audio_compression",
|
|
|
|
"Audio compression",
|
|
|
|
options=[
|
|
|
|
Option("adpcm", "ADPCM"),
|
|
|
|
Option("none", "None"),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
DropdownInput(
|
|
|
|
"fft_compression",
|
|
|
|
"Waterfall compression",
|
|
|
|
options=[
|
|
|
|
Option("adpcm", "ADPCM"),
|
|
|
|
Option("none", "None"),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Section(
|
|
|
|
"Display settings",
|
2021-03-24 22:43:19 +00:00
|
|
|
DropdownInput(
|
2021-03-01 00:19:06 +00:00
|
|
|
"tuning_precision",
|
|
|
|
"Tuning precision",
|
2021-03-24 22:43:19 +00:00
|
|
|
options=[Option(str(i), "{} Hz".format(10 ** i)) for i in range(0, 6)],
|
2021-03-30 22:18:06 +00:00
|
|
|
converter=IntConverter(),
|
2021-02-15 14:40:37 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Section(
|
|
|
|
"Map settings",
|
|
|
|
TextInput(
|
|
|
|
"google_maps_api_key",
|
|
|
|
"Google Maps API key",
|
|
|
|
infotext="Google Maps requires an API key, check out "
|
|
|
|
+ '<a href="https://developers.google.com/maps/documentation/embed/get-api-key" target="_blank">'
|
|
|
|
+ "their documentation</a> on how to obtain one.",
|
|
|
|
),
|
|
|
|
NumberInput(
|
|
|
|
"map_position_retention_time",
|
|
|
|
"Map retention time",
|
|
|
|
infotext="Specifies how log markers / grids will remain visible on the map",
|
|
|
|
append="s",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2020-03-26 22:04:02 +00:00
|
|
|
|
2021-05-07 15:19:11 +00:00
|
|
|
def remove_existing_image(self, image_id):
|
|
|
|
config = CoreConfig()
|
|
|
|
# remove all possible file extensions
|
|
|
|
for ext in ["png", "jpg", "webp"]:
|
|
|
|
try:
|
|
|
|
os.unlink("{}/{}.{}".format(config.get_data_directory(), image_id, ext))
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
2021-02-08 22:36:46 +00:00
|
|
|
def handle_image(self, data, image_id):
|
2021-02-10 20:29:46 +00:00
|
|
|
if image_id in data:
|
2021-02-08 23:38:59 +00:00
|
|
|
config = CoreConfig()
|
2021-02-10 20:29:46 +00:00
|
|
|
if data[image_id] == "restore":
|
2021-05-07 15:19:11 +00:00
|
|
|
self.remove_existing_image(image_id)
|
2021-02-10 20:29:46 +00:00
|
|
|
elif data[image_id]:
|
2021-02-10 23:20:17 +00:00
|
|
|
if not data[image_id].startswith(image_id):
|
|
|
|
logger.warning("invalid file name: %s", data[image_id])
|
|
|
|
else:
|
2021-05-07 14:57:54 +00:00
|
|
|
# get file extension (at least 3 characters)
|
|
|
|
# should be all lowercase since they are set by the upload script
|
|
|
|
pattern = re.compile(".*\\.([a-z]{3,})$")
|
|
|
|
matches = pattern.match(data[image_id])
|
|
|
|
if matches is None:
|
|
|
|
logger.warning("could not determine file extension for %s", image_id)
|
|
|
|
else:
|
2021-05-07 15:19:11 +00:00
|
|
|
self.remove_existing_image(image_id)
|
2021-05-07 14:57:54 +00:00
|
|
|
ext = matches.group(1)
|
|
|
|
data_file = "{}/{}.{}".format(config.get_data_directory(), image_id, ext)
|
|
|
|
temporary_file = "{}/{}".format(config.get_temporary_directory(), data[image_id])
|
|
|
|
shutil.copy(temporary_file, data_file)
|
2021-02-10 20:29:46 +00:00
|
|
|
del data[image_id]
|
2021-02-10 21:24:43 +00:00
|
|
|
# remove any accumulated temporary files on save
|
|
|
|
for file in glob("{}/{}*".format(config.get_temporary_directory(), image_id)):
|
|
|
|
os.unlink(file)
|
2021-02-08 22:36:46 +00:00
|
|
|
|
2021-02-15 14:40:37 +00:00
|
|
|
def processData(self, data):
|
2021-02-08 22:36:46 +00:00
|
|
|
# Image handling
|
2021-02-10 21:25:43 +00:00
|
|
|
for img in ["receiver_avatar", "receiver_top_photo"]:
|
|
|
|
self.handle_image(data, img)
|
2021-02-16 17:12:10 +00:00
|
|
|
# special handling for waterfall colors: custom colors only stay in config if custom color scheme is selected
|
|
|
|
if "waterfall_scheme" in data:
|
|
|
|
scheme = WaterfallOptions(data["waterfall_scheme"])
|
|
|
|
if scheme is not WaterfallOptions.CUSTOM and "waterfall_colors" in data:
|
|
|
|
data["waterfall_colors"] = None
|
2021-02-15 14:40:37 +00:00
|
|
|
super().processData(data)
|