ProjectsOld/House-Dashboard/House-Dashboard/Functions/Tabs.cs
2018-05-02 18:33:27 +02:00

86 lines
2.8 KiB
C#

using System;
using System.Net.Cache;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using BlubbFish.House.Dashboard.Graphics;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector;
namespace BlubbFish.House.Dashboard.Functions {
class Tabs {
private InIReader ini;
private ADataBackend data;
private TabItem tab;
public Tabs(InIReader settings, ADataBackend data) {
this.ini = settings;
this.data = data;
}
internal TabItem GetTab() {
this.tab = new TabItem();
this.GenerateHeader();
this.GenerateContent();
return this.tab;
}
private void GenerateContent() {
Grid g = new Grid {
Background = new BrushConverter().ConvertFromString("#FFE5E5E5") as SolidColorBrush
};
if (this.ini.GetValue("general", "background-image") != null) {
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.None;
bitmap.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bitmap.UriSource = new Uri(this.ini.GetValue("general", "background-image"), UriKind.RelativeOrAbsolute);
bitmap.EndInit();
Image bgimage = new Image {
Source = bitmap
};
g.Children.Add(bgimage);
}
foreach (String item in this.ini.GetSections(false)) {
if(item != "general") {
AGraphics a = AGraphics.GetInstance(this.ini.GetSection(item), this.data);
if (a != null) {
g.Children.Add(a.Draw());
}
}
}
this.tab.Content = g;
}
private void GenerateHeader() {
StackPanel header = new StackPanel {
Orientation = Orientation.Horizontal
};
if (this.ini.GetValue("general", "icon") != null) {
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.None;
bitmap.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bitmap.UriSource = new Uri(this.ini.GetValue("general", "icon"), UriKind.RelativeOrAbsolute);
bitmap.EndInit();
Image image = new Image {
Source = bitmap
};
header.Children.Add(image);
}
if (this.ini.GetValue("general", "name") != null) {
TextBlock t = new TextBlock {
Text = this.ini.GetValue("general", "name"),
FontSize = 20
};
header.Children.Add(t);
}
this.tab.Header = header;
}
}
}