forked from LMS-Community/plugin-Qobuz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.pm
66 lines (50 loc) · 1.96 KB
/
Settings.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package Plugins::Qobuz::Settings;
use strict;
use base qw(Slim::Web::Settings);
use Slim::Utils::Prefs;
use Slim::Utils::Log;
use Digest::MD5 qw(md5_hex);
# Used for logging.
my $log = Slim::Utils::Log->addLogCategory({
'category' => 'plugin.qobuz',
'defaultLevel' => 'INFO',
'description' => 'Qobuz Settings',
});
my $prefs = preferences('plugin.qobuz');
sub name {
return Slim::Web::HTTP::CSRF->protectName('PLUGIN_QOBUZ');
}
sub page {
return Slim::Web::HTTP::CSRF->protectURI('plugins/Qobuz/settings/basic.html');
}
sub prefs {
return ($prefs, 'filterSearchResults', 'playSamples');
}
sub handler {
my ($class, $client, $params) = @_;
if ($params->{'saveSettings'} && $params->{'username'}) {
if ($params->{'username'}) {
my $username = $params->{'username'};
$prefs->set('username', "$username"); # add a leading space to make the message display nicely
}
if ($params->{'password'} && ($params->{'password'} ne "****")) {
my $password_md5_hash = md5_hex($params->{'password'});
$prefs->set('password_md5_hash', "$password_md5_hash"); # add a leading space to make the message display nicely
}
if ($params->{'preferredFormat'}) {
my $preferredFormat = $params->{'preferredFormat'};
$prefs->set('preferredFormat', "$preferredFormat"); # add a leading space to make the message display nicely
}
$params->{pref_filterSearchResults} ||= 0;
$params->{pref_playSamples} ||= 0;
}
# This puts the value on the webpage.
# If the page is just being displayed initially, then this puts the current value found in prefs on the page.
$params->{'prefs'}->{'username'} = $prefs->get('username');
$params->{'prefs'}->{'password_md5_hash'} = "****";
$params->{'prefs'}->{'preferredFormat'} = $prefs->get('preferredFormat');
# I have no idea what this does, but it seems important and it's not plugin-specific.
return $class->SUPER::handler($client, $params);
}
1;
__END__