mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
FW_makeImage creates <img src="..."><!-- pathname --> for icons
icons only read once at definition of FHEMWEB device set ... rereadicons git-svn-id: https://svn.fhem.de/fhem/trunk@1768 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
75f6c7743c
commit
4cd1c5a9c9
@ -2,6 +2,11 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
|
#
|
||||||
|
# #Todo:
|
||||||
|
# 3) logical icons should contain no extension, initial icon search uses any graphics type of png, gif, jpg
|
||||||
|
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use TcpServerUtils;
|
use TcpServerUtils;
|
||||||
@ -19,8 +24,11 @@ sub FW_fileList($);
|
|||||||
sub FW_logWrapper($);
|
sub FW_logWrapper($);
|
||||||
sub FW_makeEdit($$$);
|
sub FW_makeEdit($$$);
|
||||||
sub FW_makeTable($$@);
|
sub FW_makeTable($$@);
|
||||||
|
sub FW_makeImage($);
|
||||||
|
sub FW_SetDirs();
|
||||||
sub FW_ReadIconsFrom($$);
|
sub FW_ReadIconsFrom($$);
|
||||||
sub FW_ReadIcons();
|
sub FW_ReadIcons($);
|
||||||
|
sub FW_GetIcons();
|
||||||
sub FW_IconURL($);
|
sub FW_IconURL($);
|
||||||
sub FW_roomOverview($);
|
sub FW_roomOverview($);
|
||||||
sub FW_select($$$$@);
|
sub FW_select($$$$@);
|
||||||
@ -71,7 +79,6 @@ my $FW_data; # Filecontent from browser when editing a file
|
|||||||
my $FW_detail; # currently selected device for detail view
|
my $FW_detail; # currently selected device for detail view
|
||||||
my %FW_devs; # hash of from/to entries per device
|
my %FW_devs; # hash of from/to entries per device
|
||||||
my %FW_icons; # List of icons
|
my %FW_icons; # List of icons
|
||||||
my $FW_iconsread; # Timestamp of last icondir check
|
|
||||||
my $FW_plotmode; # Global plot mode (WEB attribute)
|
my $FW_plotmode; # Global plot mode (WEB attribute)
|
||||||
my $FW_plotsize; # Global plot size (WEB attribute)
|
my $FW_plotsize; # Global plot size (WEB attribute)
|
||||||
my $FW_commandref; # $FW_docdir/commandref.html;
|
my $FW_commandref; # $FW_docdir/commandref.html;
|
||||||
@ -99,6 +106,7 @@ FHEMWEB_Initialize($)
|
|||||||
|
|
||||||
$hash->{ReadFn} = "FW_Read";
|
$hash->{ReadFn} = "FW_Read";
|
||||||
$hash->{GetFn} = "FW_Get";
|
$hash->{GetFn} = "FW_Get";
|
||||||
|
$hash->{SetFn} = "FW_Set";
|
||||||
$hash->{AttrFn} = "FW_Attr";
|
$hash->{AttrFn} = "FW_Attr";
|
||||||
$hash->{DefFn} = "FW_Define";
|
$hash->{DefFn} = "FW_Define";
|
||||||
$hash->{UndefFn} = "FW_Undef";
|
$hash->{UndefFn} = "FW_Undef";
|
||||||
@ -147,6 +155,11 @@ FW_Define($$)
|
|||||||
return "Usage: define <name> FHEMWEB [IPV6:]<tcp-portnr> [global]"
|
return "Usage: define <name> FHEMWEB [IPV6:]<tcp-portnr> [global]"
|
||||||
if($port !~ m/^(IPV6:)?\d+$/ || ($global && $global ne "global"));
|
if($port !~ m/^(IPV6:)?\d+$/ || ($global && $global ne "global"));
|
||||||
|
|
||||||
|
|
||||||
|
FW_SetDirs;
|
||||||
|
FW_ReadIcons($hash); # we do it only once at startup to save ressources at runtime
|
||||||
|
|
||||||
|
|
||||||
my $ret = TcpServer_Open($hash, $port, $global);
|
my $ret = TcpServer_Open($hash, $port, $global);
|
||||||
|
|
||||||
# Make sure that fhem only runs once
|
# Make sure that fhem only runs once
|
||||||
@ -154,6 +167,7 @@ FW_Define($$)
|
|||||||
Log 1, "$ret. Exiting.";
|
Log 1, "$ret. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,12 +387,10 @@ FW_AnswerCall($)
|
|||||||
$FW_RETTYPE = "text/html; charset=$FW_encoding";
|
$FW_RETTYPE = "text/html; charset=$FW_encoding";
|
||||||
$FW_ME = "/" . AttrVal($FW_wname, "webname", "fhem");
|
$FW_ME = "/" . AttrVal($FW_wname, "webname", "fhem");
|
||||||
|
|
||||||
FW_SetDirs;
|
|
||||||
|
|
||||||
$FW_commandref = "$FW_docdir/commandref.html";
|
$FW_commandref = "$FW_docdir/commandref.html";
|
||||||
#Debug "commandref.html is at $FW_commandref";
|
#Debug "commandref.html is at $FW_commandref";
|
||||||
|
|
||||||
|
FW_GetIcons(); # get the icon set for the current instance
|
||||||
|
|
||||||
$MW_dir = AttrVal($FW_wname, "fwmodpath", "$attr{global}{modpath}/FHEM");
|
$MW_dir = AttrVal($FW_wname, "fwmodpath", "$attr{global}{modpath}/FHEM");
|
||||||
$FW_ss = AttrVal($FW_wname, "smallscreen", 0);
|
$FW_ss = AttrVal($FW_wname, "smallscreen", 0);
|
||||||
@ -401,7 +413,6 @@ FW_AnswerCall($)
|
|||||||
|
|
||||||
elsif($arg =~ m,^$FW_ME/icons/(.*)$,) {
|
elsif($arg =~ m,^$FW_ME/icons/(.*)$,) {
|
||||||
my ($icon,$cachable) = ($1, 1);
|
my ($icon,$cachable) = ($1, 1);
|
||||||
FW_ReadIcons();
|
|
||||||
|
|
||||||
#Debug "You want $icon which is " . $FW_icons{$icon};
|
#Debug "You want $icon which is " . $FW_icons{$icon};
|
||||||
# if we do not have the icon, we convert the device state to the icon name
|
# if we do not have the icon, we convert the device state to the icon name
|
||||||
@ -731,6 +742,19 @@ FW_makeSelect($$$$)
|
|||||||
FW_pO "</form>";
|
FW_pO "</form>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##############################
|
||||||
|
sub
|
||||||
|
FW_makeImage($) {
|
||||||
|
|
||||||
|
my ($name)= @_;
|
||||||
|
my $iconpath= FW_IconPath($name);
|
||||||
|
if(defined($iconpath)) {
|
||||||
|
my $iconurl= FW_IconURL($name);
|
||||||
|
return "<img src=\"$iconurl\"><!-- $iconpath -->";
|
||||||
|
} else {
|
||||||
|
return "<b>Image <i>$name</i> not found in $FW_icondir</b>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
sub
|
sub
|
||||||
@ -811,7 +835,7 @@ FW_roomOverview($)
|
|||||||
$FW_room = $1 if($FW_room && $FW_room =~ m/^([^,]*),/);
|
$FW_room = $1 if($FW_room && $FW_room =~ m/^([^,]*),/);
|
||||||
$FW_room = "" if(!$FW_room);
|
$FW_room = "" if(!$FW_room);
|
||||||
FW_pHPlain "room=$FW_room",
|
FW_pHPlain "room=$FW_room",
|
||||||
"<div id=\"back\"><img src=\"$FW_ME/icons/back.png\"></div>";
|
"<div id=\"back\">" . FW_makeImage("back") . "</div>";
|
||||||
FW_pO "<div id=\"menu\">$FW_detail details</div>";
|
FW_pO "<div id=\"menu\">$FW_detail details</div>";
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -904,7 +928,7 @@ FW_roomOverview($)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
FW_ReadIcons();
|
FW_GetIcons(); # get the icon set for the current instance
|
||||||
foreach(my $idx = 0; $idx < @list1; $idx++) {
|
foreach(my $idx = 0; $idx < @list1; $idx++) {
|
||||||
my ($l1, $l2) = ($list1[$idx], $list2[$idx]);
|
my ($l1, $l2) = ($list1[$idx], $list2[$idx]);
|
||||||
if(!$l1) {
|
if(!$l1) {
|
||||||
@ -940,8 +964,7 @@ FW_showRoom()
|
|||||||
{
|
{
|
||||||
return if(!$FW_room);
|
return if(!$FW_room);
|
||||||
|
|
||||||
# (re-) list the icons
|
FW_GetIcons(); # get the icon set for the current instance
|
||||||
FW_ReadIcons();
|
|
||||||
|
|
||||||
FW_pO "<form method=\"get\" action=\"$FW_ME\">";
|
FW_pO "<form method=\"get\" action=\"$FW_ME\">";
|
||||||
FW_pO "<div id=\"content\">";
|
FW_pO "<div id=\"content\">";
|
||||||
@ -982,7 +1005,7 @@ FW_showRoom()
|
|||||||
pF "\n<tr class=\"%s\">", ($row&1)?"odd":"even";
|
pF "\n<tr class=\"%s\">", ($row&1)?"odd":"even";
|
||||||
my $devName = AttrVal($d, "alias", $d);
|
my $devName = AttrVal($d, "alias", $d);
|
||||||
my $icon = AttrVal($d, "icon", "");
|
my $icon = AttrVal($d, "icon", "");
|
||||||
$icon = "<img src=\"$FW_ME/icons/$icon\"> " if($icon);
|
$icon = FW_makeImage($icon) . " " if($icon);
|
||||||
|
|
||||||
if($FW_hiddenroom{detail}) {
|
if($FW_hiddenroom{detail}) {
|
||||||
FW_pO "<td><div class=\"col1\">$icon$devName</div></td>";
|
FW_pO "<td><div class=\"col1\">$icon$devName</div></td>";
|
||||||
@ -1728,17 +1751,6 @@ FW_style($$)
|
|||||||
$fName = $FW_webArgs{saveName}
|
$fName = $FW_webArgs{saveName}
|
||||||
if($FW_webArgs{saveAs} && $FW_webArgs{saveName});
|
if($FW_webArgs{saveAs} && $FW_webArgs{saveName});
|
||||||
|
|
||||||
#$fName =~ s,/,,g; # little bit of security
|
|
||||||
#$fName = ($fName eq "fhem.cfg" ? $attr{global}{configfile} :
|
|
||||||
# "$FW_dir/$fName");
|
|
||||||
#if($fName eq "fhem.cfg") {
|
|
||||||
# $fName = $attr{global}{configfile};
|
|
||||||
#} elsif ($fName =~ m/.*(sh|Util.*|cfg|holiday)/ && $fName ne "fhem.cfg") {
|
|
||||||
# $fName = "$MW_dir/$fName";
|
|
||||||
#} else {
|
|
||||||
# $fName = "$FW_dir/$fName";
|
|
||||||
#}
|
|
||||||
|
|
||||||
if(!open(FH, ">$fName")) {
|
if(!open(FH, ">$fName")) {
|
||||||
FW_pO "$fName: $!";
|
FW_pO "$fName: $!";
|
||||||
return;
|
return;
|
||||||
@ -1754,13 +1766,13 @@ FW_style($$)
|
|||||||
$ret = "";
|
$ret = "";
|
||||||
|
|
||||||
} elsif($a[1] eq "iconFor") {
|
} elsif($a[1] eq "iconFor") {
|
||||||
FW_ReadIcons();
|
FW_GetIcons(); # get the icon set for the current instance
|
||||||
FW_pO "<div id=\"content\"><table class=\"iconFor\">";
|
FW_pO "<div id=\"content\"><table class=\"iconFor\">";
|
||||||
foreach my $i (sort grep {/^ico/} keys %FW_icons) {
|
foreach my $i (sort grep {/^ico/} keys %FW_icons) {
|
||||||
FW_pO "<tr><td>";
|
FW_pO "<tr><td>";
|
||||||
FW_pO "<a href=\"$FW_ME?cmd=attr $a[2] icon $i\">$i</a>";
|
FW_pO "<a href=\"$FW_ME?cmd=attr $a[2] icon $i\">$i</a>";
|
||||||
FW_pO "</td><td>";
|
FW_pO "</td><td>";
|
||||||
FW_pO "<img src=\"$FW_ME/icons/$i\">";
|
FW_pO FW_makeImage($i);
|
||||||
FW_pO "</td></tr>";
|
FW_pO "</td></tr>";
|
||||||
}
|
}
|
||||||
FW_pO "</table></div>";
|
FW_pO "</table></div>";
|
||||||
@ -2007,7 +2019,7 @@ FW_ReadIconsFrom($$) {
|
|||||||
|
|
||||||
my ($prepend,$dir)= @_;
|
my ($prepend,$dir)= @_;
|
||||||
|
|
||||||
#Debug "read icons from \"$dir\", prepend \"$prepend\"";
|
#Debug "read icons from \"${FW_icondir}/${dir}\", prepend \"$prepend\"";
|
||||||
|
|
||||||
my (@entries, @filenames);
|
my (@entries, @filenames);
|
||||||
if(opendir(DH, "${FW_icondir}/${dir}")) {
|
if(opendir(DH, "${FW_icondir}/${dir}")) {
|
||||||
@ -2038,28 +2050,38 @@ FW_ReadIconsFrom($$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
FW_ReadIcons()
|
FW_ReadIcons($)
|
||||||
{
|
{
|
||||||
my $now = time();
|
my ($hash)= @_;
|
||||||
return if($FW_iconsread && ($now - $FW_iconsread) <= 5);
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
%FW_icons = ();
|
%FW_icons = ();
|
||||||
# read icons from default directory
|
# read icons from default directory
|
||||||
FW_ReadIconsFrom("", "default");
|
FW_ReadIconsFrom("", "default");
|
||||||
# read icons from stylesheet specific directory, icons found here supersede default icons with same name
|
# read icons from stylesheet specific directory, icons found here supersede default icons with same name
|
||||||
my $prefix= AttrVal($FW_wname, "stylesheetPrefix", "");
|
my $prefix= AttrVal($name, "stylesheetPrefix", "");
|
||||||
FW_ReadIconsFrom("", "$prefix") unless($prefix eq "");
|
FW_ReadIconsFrom("", "$prefix") unless($prefix eq "");
|
||||||
# read icons from explicit directory, icons found here supersede all other icons with same name
|
# read icons from explicit directory, icons found here supersede all other icons with same name
|
||||||
my $iconpath= AttrVal($FW_wname, "iconpath", "");
|
my $iconpath= AttrVal($name, "iconpath", "");
|
||||||
FW_ReadIconsFrom("", "$iconpath") unless($iconpath eq "");
|
FW_ReadIconsFrom("", "$iconpath") unless($iconpath eq "");
|
||||||
# if now icons were found so far, read icons from icondir itself
|
# if now icons were found so far, read icons from icondir itself
|
||||||
FW_ReadIconsFrom("", "") unless(%FW_icons);
|
FW_ReadIconsFrom("", "") unless(%FW_icons);
|
||||||
|
|
||||||
$FW_iconsread = $now;
|
$hash->{fhem}{icons}= join(":", %FW_icons);
|
||||||
|
|
||||||
#foreach my $k (keys %FW_icons) {
|
Log 4, "$name: Icon dictionary for $FW_icondir follows...";
|
||||||
# Debug " icon: $k => " . $FW_icons{$k};
|
foreach my $k (keys %FW_icons) {
|
||||||
#}
|
Log 4, " $k => " . $FW_icons{$k};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# get the icon set from the device
|
||||||
|
sub
|
||||||
|
FW_GetIcons() {
|
||||||
|
#Debug "Getting icons for $FW_wname.";
|
||||||
|
my $hash= $defs{$FW_wname};
|
||||||
|
%FW_icons= split(":", $hash->{fhem}{icons});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
@ -2079,7 +2101,7 @@ FW_IconPath($) {
|
|||||||
my ($name)= @_;
|
my ($name)= @_;
|
||||||
$name =~ s/\.(png)$//; # FIXME
|
$name =~ s/\.(png)$//; # FIXME
|
||||||
$name= "${name}.png"; # FIXME
|
$name= "${name}.png"; # FIXME
|
||||||
FW_ReadIcons() unless($FW_iconsread);
|
FW_GetIcons(); # get the icon set for the current instance
|
||||||
my $path= $FW_icons{$name};
|
my $path= $FW_icons{$name};
|
||||||
return $path ? $FW_icondir. $path : undef;
|
return $path ? $FW_icondir. $path : undef;
|
||||||
}
|
}
|
||||||
@ -2202,7 +2224,7 @@ FW_Notify($$)
|
|||||||
|
|
||||||
my $rn = AttrVal($dn, "room", "");
|
my $rn = AttrVal($dn, "room", "");
|
||||||
if($filter eq "all" || $rn =~ m/\b$filter\b/) {
|
if($filter eq "all" || $rn =~ m/\b$filter\b/) {
|
||||||
FW_ReadIcons();
|
FW_GetIcons(); # get the icon set for the current instance
|
||||||
|
|
||||||
my @old = ($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp, $FW_subdir);
|
my @old = ($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp, $FW_subdir);
|
||||||
$FW_wname = $ntfy->{SNAME};
|
$FW_wname = $ntfy->{SNAME};
|
||||||
@ -2327,6 +2349,7 @@ FW_devState($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
sub FW_Get($@) {
|
sub FW_Get($@) {
|
||||||
|
|
||||||
my ($hash, @a) = @_;
|
my ($hash, @a) = @_;
|
||||||
@ -2336,14 +2359,29 @@ sub FW_Get($@) {
|
|||||||
return "Unknown argument $a[1], choose one of " . "icon"
|
return "Unknown argument $a[1], choose one of " . "icon"
|
||||||
unless($a[1] eq "icon");
|
unless($a[1] eq "icon");
|
||||||
|
|
||||||
|
$FW_wname= $hash->{NAME};
|
||||||
my $icon= FW_IconPath($a[2]);
|
my $icon= FW_IconPath($a[2]);
|
||||||
return defined($icon) ? $icon : "no such icon";
|
return defined($icon) ? $icon : "no such icon";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
sub FW_Set($@) {
|
||||||
|
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
|
return "syntax error" if(int(@a) != 2);
|
||||||
|
|
||||||
|
return "Unknown argument $a[1], choose one of " . "rereadicons"
|
||||||
|
unless($a[1] eq "rereadicons");
|
||||||
|
|
||||||
|
FW_ReadIcons($hash);
|
||||||
|
return undef;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user