2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

contrib/InfoPanel: updated

git-svn-id: https://svn.fhem.de/fhem/trunk@7816 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2015-02-01 13:36:06 +00:00
parent c479ea3cd5
commit d8c7353528
2 changed files with 30 additions and 28 deletions

View File

@ -1,4 +1,4 @@
# $Id$ # $Id: configDB.pm 7696 2015-01-24 18:16:54Z betateilchen $
############################################################################## ##############################################################################
# #
@ -140,7 +140,7 @@ sub __cfgDB_Diff($$$$);
sub _cfgDB_InsertLine($$$$); sub _cfgDB_InsertLine($$$$);
sub _cfgDB_Execute($@); sub _cfgDB_Execute($@);
sub _cfgDB_Filedelete($); sub _cfgDB_Filedelete($);
sub _cfgDB_Fileexport($); sub _cfgDB_Fileexport($;$);
sub _cfgDB_Filelist(;$); sub _cfgDB_Filelist(;$);
sub _cfgDB_Info(); sub _cfgDB_Info();
sub _cfgDB_Migrate(); sub _cfgDB_Migrate();
@ -568,7 +568,7 @@ sub cfgDB_MigrationImport() {
# return SVN Id, called by fhem's CommandVersion # return SVN Id, called by fhem's CommandVersion
sub cfgDB_svnId() { sub cfgDB_svnId() {
return "# ".'$Id$' return "# ".'$Id: configDB.pm 7696 2015-01-24 18:16:54Z betateilchen $'
} }
# return filelist depending on directory and regexp # return filelist depending on directory and regexp
@ -975,8 +975,8 @@ sub _cfgDB_Filedelete($) {
} }
# export file from database to filesystem # export file from database to filesystem
sub _cfgDB_Fileexport($) { sub _cfgDB_Fileexport($;$) {
my ($filename) = @_; my ($filename,$raw) = @_;
my $fhem_dbh = _cfgDB_Connect; my $fhem_dbh = _cfgDB_Connect;
my $sth = $fhem_dbh->prepare( "SELECT content FROM fhembinfilesave WHERE filename = '$filename'" ); my $sth = $fhem_dbh->prepare( "SELECT content FROM fhembinfilesave WHERE filename = '$filename'" );
$sth->execute(); $sth->execute();
@ -991,7 +991,8 @@ sub _cfgDB_Fileexport($) {
$sth->finish(); $sth->finish();
$fhem_dbh->disconnect(); $fhem_dbh->disconnect();
return "$counter bytes written from database into file $filename"; return "$counter bytes written from database into file $filename" unless $raw;
return ($blobContent,$counter);
} }
# import file into database # import file into database

View File

@ -80,7 +80,7 @@ sub InfoPanel_Initialize($) {
$hash->{DefFn} = "btIP_Define"; $hash->{DefFn} = "btIP_Define";
$hash->{UndefFn} = "btIP_Undef"; $hash->{UndefFn} = "btIP_Undef";
#$hash->{AttrFn} = "btIP_Attr"; #$hash->{AttrFn} = "btIP_Attr";
$hash->{AttrList} = "autoreload:1,0 bg bgcolor refresh size title tmin"; $hash->{AttrList} = "disable:0,1,toggle autoreload:1,0 bg bgcolor refresh size title tmin";
$hash->{SetFn} = "btIP_Set"; $hash->{SetFn} = "btIP_Set";
$hash->{NotifyFn} = "btIP_Notify"; $hash->{NotifyFn} = "btIP_Notify";
@ -272,24 +272,24 @@ sub btIP_itemImg {
$id = ($id eq '-') ? createUniqueId() : $id; $id = ($id eq '-') ? createUniqueId() : $id;
return unless(defined($arg)); return unless(defined($arg));
return if($arg eq ""); return if($arg eq "");
my ($data,$info,$width,$height,$mimetype,$output); my ($counter,$data,$info,$width,$height,$mimetype,$output);
if($srctype eq 'file') { if($srctype eq 'file') {
my (@d,$err); Log3(undef,4,"InfoPanel: looking for img $arg");
$err = "";
Log3(undef,4,"InfoPanel img name: $arg");
($err,@d) = FileRead($arg);
if($err && configDBUsed()) {
# not found in database, try to read from filesystem
Log3(undef,4,"Infopanel forced read $arg");
$err = undef;
($err,@d) = FileRead({FileName => $arg, ForceType =>'file'});
Log3(undef,4,"Infopanel: forced read error file: $arg") if $err;
Log3(undef,4,"Infopanel: forced read found: $arg") if !$err;
}
$data = join("",@d) unless $err;
if(configDBUsed()){
Log3(undef,4,"InfoPanel: reading from configDB");
($data,$counter) = _cfgDB_Fileexport($arg,1);
}
if(!$counter) {
Log3(undef,4,"InfoPanel: reading from filesystem");
my $length = -s "$arg";
open(GRAFIK, "<", $arg) or die("File not found $!");
binmode(GRAFIK);
$counter = read(GRAFIK, $data, $length);
close(GRAFIK);
}
} elsif ($srctype eq "url" || $srctype eq "urlq") { } elsif ($srctype eq "url" || $srctype eq "urlq") {
if($srctype eq "url") { if($srctype eq "url") {
$data= GetFileFromURL($arg,3,undef,1); $data= GetFileFromURL($arg,3,undef,1);
@ -303,8 +303,9 @@ sub btIP_itemImg {
return ""; return "";
} }
($width,$height,$data) = _btIP_imgData($data,$scale); ($width,$height,$mimetype,$data) = _btIP_imgData($data,$scale);
$output = "<image id=\"$id\" x=\"$x\" y=\"$y\" width=\"".$width."px\" height=\"".$height."px\" \nxlink:href=\"$data\" />\n"; $output = "<!-- w: $width h: $height t: $mimetype-->\n";
$output .= "<image id=\"$id\" x=\"$x\" y=\"$y\" width=\"".$width."px\" height=\"".$height."px\" \nxlink:href=\"$data\" />\n";
return $output; return $output;
} }
@ -316,7 +317,7 @@ sub _btIP_imgData {
($width,$height)= _btIP_imgRescale($width,$height,$scale) unless $scale eq '1'; ($width,$height)= _btIP_imgRescale($width,$height,$scale) unless $scale eq '1';
my $mimetype = $info->{file_media_type}; my $mimetype = $info->{file_media_type};
my $data = "data:$mimetype;base64,".encode_base64($arg); my $data = "data:$mimetype;base64,".encode_base64($arg);
return ($width,$height,$data); return ($width,$height,$mimetype,$data);
} }
sub _btIP_imgRescale { sub _btIP_imgRescale {
@ -515,13 +516,13 @@ sub btIP_returnSVG($) {
my ($width,$height)= split(/x/, AttrVal($name,"size","800x600")); my ($width,$height)= split(/x/, AttrVal($name,"size","800x600"));
my $bgcolor = AttrVal($name,'bgcolor','000000'); my $bgcolor = AttrVal($name,'bgcolor','000000');
my $svg = ""; our $svg = "";
eval { eval {
$svg = "\n<svg \n". $svg = "\n<svg \n".
"xmlns=\"http://www.w3.org/2000/svg\"\nxmlns:xlink=\"http://www.w3.org/1999/xlink\"\n". "xmlns=\"http://www.w3.org/2000/svg\"\nxmlns:xlink=\"http://www.w3.org/1999/xlink\"\n".
"width=\"".$width."px\" height=\"".$height."px\" \n ". "width=\"".$width."px\" height=\"".$height."px\" \n".
"viewPort=\"0 0 $width $height\"\n". "viewPort=\"0 0 $width $height\"\n".
"style=\"stroke-width: 0px; background-color:$bgcolor; "; "style=\"stroke-width: 0px; background-color:$bgcolor; ";
@ -594,7 +595,7 @@ sub btIP_returnSVG($) {
} # end defined() } # end defined()
$svg .= "\" >\n\n"; $svg .= "\" >\n\n";
$svg .= btIP_evalLayout($svg, $name, $defs{$name}{fhem}{layout}); $svg = btIP_evalLayout($svg, $name, $defs{$name}{fhem}{layout});
$defs{$name}{STATE} = localtime(); $defs{$name}{STATE} = localtime();