From e21b66b8610ff994f9eaac802ce883e0da64e759 Mon Sep 17 00:00:00 2001
From: borisneubert <>
Date: Sat, 18 Aug 2012 15:20:27 +0000
Subject: [PATCH] 01_FHEMWEB now uses logical icon names images/icons can be of
gif ico jpg png type 95_FLOORPLAN and stylesheets adjusted to use logical
icon names
git-svn-id: https://svn.fhem.de/fhem/trunk@1805 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/webfrontend/pgm2/01_FHEMWEB.pm | 86 +++++++++++---------
fhem/webfrontend/pgm2/95_FLOORPLAN.pm | 40 +++++----
fhem/webfrontend/pgm2/darkfloorplanstyle.css | 6 +-
fhem/webfrontend/pgm2/darkstyle.css | 2 +-
fhem/webfrontend/pgm2/floorplanstyle.css | 6 +-
fhem/webfrontend/pgm2/smallscreenstyle.css | 2 +-
fhem/webfrontend/pgm2/style.css | 2 +-
fhem/webfrontend/pgm2/touchpadstyle.css | 2 +-
8 files changed, 80 insertions(+), 66 deletions(-)
diff --git a/fhem/webfrontend/pgm2/01_FHEMWEB.pm b/fhem/webfrontend/pgm2/01_FHEMWEB.pm
index e113ef3ed..a419bb6a3 100755
--- a/fhem/webfrontend/pgm2/01_FHEMWEB.pm
+++ b/fhem/webfrontend/pgm2/01_FHEMWEB.pm
@@ -2,11 +2,6 @@
# $Id$
package main;
-#
-# #Todo:
-# 3) logical icons should contain no extension, initial icon search uses any graphics type of png, gif, jpg
-
-
use strict;
use warnings;
use TcpServerUtils;
@@ -98,6 +93,12 @@ my $FW_chash; # client fhem hash
my $FW_encoding="UTF-8";
+my $ICONEXTENSION = "gif|ico|png|jpg"; # don't forget to amend FW_ServeSpecial if you change this!
+
+# FIXME
+# use constant FOO => BAR
+# is better but then I cannot use FOO in a regexp. Any ideas how to fix it?
+
#####################################
sub
FHEMWEB_Initialize($)
@@ -306,7 +307,7 @@ FW_ServeSpecial($$$) {
#Debug "We serve $dir/$file.$ext";
open(FH, "$dir/$file.$ext") || return 0;
- binmode(FH) if($ext =~ m/gif|png|jpg/); # necessary for Windows
+ binmode(FH) if($ext =~ m/$ICONEXTENSION/); # necessary for Windows
FW_pO join("", "
- if($FW_icons{"ico${l1}.png"});
+ # image tag if we have an icon, else empty
+ my $icon= $FW_icons{"ico${l1}"} ? FW_makeImage("ico${l1}") . " " : "";
if($l2 =~ m/.html$/ || $l2 =~ m/^http/) {
FW_pO "
$icon$l1 ";
@@ -1005,6 +1006,9 @@ FW_showRoom()
pF "\n", ($row&1)?"odd":"even";
my $devName = AttrVal($d, "alias", $d);
my $icon = AttrVal($d, "icon", "");
+ if($icon =~ m/^(.*)\.($ICONEXTENSION)$/) {
+ $icon= $1; # silently remove the extension
+ }
$icon = FW_makeImage($icon) . " " if($icon);
if($FW_hiddenroom{detail}) {
@@ -1172,10 +1176,10 @@ FW_logWrapper($)
} else {
FW_pO "
";
- FW_zoomLink("cmd=$cmd;zoom=-1", "Zoom-in.png", "zoom in");
- FW_zoomLink("cmd=$cmd;zoom=1", "Zoom-out.png","zoom out");
- FW_zoomLink("cmd=$cmd;off=-1", "Prev.png", "prev");
- FW_zoomLink("cmd=$cmd;off=1", "Next.png", "next");
+ FW_zoomLink("cmd=$cmd;zoom=-1", "Zoom-in", "zoom in");
+ FW_zoomLink("cmd=$cmd;zoom=1", "Zoom-out","zoom out");
+ FW_zoomLink("cmd=$cmd;off=-1", "Prev", "prev");
+ FW_zoomLink("cmd=$cmd;off=1", "Next", "next");
FW_pO "";
FW_pO " ";
my $logtype = $defs{$d}{TYPE};
@@ -1954,10 +1958,10 @@ FW_showWeblink($$$$)
($defs{$d}{WLTYPE} eq "fileplot" || $defs{$d}{WLTYPE} eq "dbplot")&&
!AttrVal($d, "fixedrange", undef)) {
- FW_zoomLink("zoom=-1", "Zoom-in.png", "zoom in");
- FW_zoomLink("zoom=1", "Zoom-out.png","zoom out");
- FW_zoomLink("off=-1", "Prev.png", "prev");
- FW_zoomLink("off=1", "Next.png", "next");
+ FW_zoomLink("zoom=-1", "Zoom-in", "zoom in");
+ FW_zoomLink("zoom=1", "Zoom-out","zoom out");
+ FW_zoomLink("off=-1", "Prev", "prev");
+ FW_zoomLink("off=1", "Next", "next");
$buttons = 0;
FW_pO "
";
}
@@ -2013,7 +2017,7 @@ FW_Attr(@)
sub
FW_ReadIconsFrom($$) {
- # recursively reads .gif .jpg .png files and returns filenames as array
+ # recursively reads .gif .ico .jpg .png files and returns filenames as array
# recursion starts at $FW_icondir/$dir
# filenames are relative to $FW_icondir
@@ -2023,27 +2027,23 @@ FW_ReadIconsFrom($$) {
my (@entries, @filenames);
if(opendir(DH, "${FW_icondir}/${dir}")) {
- @entries= sort readdir(DH); # assures order: .gif .jpg .png
+ @entries= sort readdir(DH); # assures order: .gif .ico .jpg .png
closedir(DH);
}
#Debug "$#entries entries found.";
foreach my $entry (@entries) {
my $filename= "$dir/$entry";
- my $iconname= "${prepend}${entry}";
- #Debug " entry: \"$entry\", filename= \"$filename\", iconname= \"$iconname\"";
+ #Debug " entry: \"$entry\", filename= \"$filename\"";
if( -d "${FW_icondir}/${filename}" ) {
# entry is a directory
- FW_ReadIconsFrom("${iconname}/", $filename) unless($entry eq "." || $entry eq "..");
+ FW_ReadIconsFrom("${prepend}${entry}/", $filename) unless($entry eq "." || $entry eq "..");
} elsif( -f "${FW_icondir}/${filename}") {
# entry is a regular file
- if($entry =~ m/\.(png|gif|jpg)$/i) {
- # extension is .gif .jpg .png
- #my $basename= $entry;
- #$basename =~ s/\.[^.]+$//; # cut extension
- # priority due to sort: .png (highest) to .gif (lowest)
- #$FW_icons{"${prepend}${basename}"}= $filenamerel;
- # store icon with extension
- $FW_icons{"${prepend}${entry}"}= $filename;
+ if($entry =~ m/^(.*)\.($ICONEXTENSION)$/i) {
+ my $logicalname= $1;
+ my $iconname= "${prepend}${logicalname}";
+ #Debug " icon: \"$iconname\"";
+ $FW_icons{$iconname}= $filename;
}
}
}
@@ -2084,11 +2084,21 @@ FW_GetIcons() {
%FW_icons= split(":", $hash->{fhem}{icons});
}
+sub
+FW_canonicalizeIcon($) {
+ my ($name)= @_;
+ if($name =~ m/^(.*)\.($ICONEXTENSION)$/) {
+ Log 1, "WARNING: argument of FW_canonicalizeIcon($name) has extension - inform the developers!";
+ $name= $1;
+ }
+ return $name;
+}
+
sub
FW_getIcon($) {
my ($name)= @_;
- my $icon= "$name.png"; # FIXME
- return $FW_icons{$icon} ? $icon : undef;
+ $name= FW_canonicalizeIcon($name);
+ return $FW_icons{$name} ? $name : undef;
}
# returns the physical absolute path relative for the logical path
@@ -2097,10 +2107,8 @@ FW_getIcon($) {
# weather/sunny -> $FW_icondir/default/weather/sunny.gif
sub
FW_IconPath($) {
-
my ($name)= @_;
- $name =~ s/\.(png)$//; # FIXME
- $name= "${name}.png"; # FIXME
+ $name= FW_canonicalizeIcon($name);
FW_GetIcons(); # get the icon set for the current instance
my $path= $FW_icons{$name};
return $path ? $FW_icondir. $path : undef;
@@ -2112,8 +2120,8 @@ FW_IconPath($) {
# weather/sunny -> /icons/sunny
sub FW_IconURL($) {
my ($name)= @_;
- $name =~ s/\.(png)$//; # FIXME
- return "$FW_ME/icons/${name}.png"; # FIXME
+ $name= FW_canonicalizeIcon($name);
+ return "$FW_ME/icons/${name}";
}
diff --git a/fhem/webfrontend/pgm2/95_FLOORPLAN.pm b/fhem/webfrontend/pgm2/95_FLOORPLAN.pm
index be39a8a97..639848763 100644
--- a/fhem/webfrontend/pgm2/95_FLOORPLAN.pm
+++ b/fhem/webfrontend/pgm2/95_FLOORPLAN.pm
@@ -1,5 +1,6 @@
################################################################################
# 95 FLOORPLAN
+# $Id $
# Feedback: http://groups.google.com/group/fhem-users
# Define Custom Floorplans
# Released : 26.02.2012
@@ -302,7 +303,7 @@ FP_htmlHeader($) {
FW_pO "
No floorplans have been defined yet. For definition, use
";
FW_pO "
";
- FW_pO 'Also check the commandrefdefine <name> FLOORPLAN
';
+ FW_pO 'Also check the commandref
';
FW_pO "