From 538f99faf7b381717079ea700d4f2e6e908537ea Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Apr 2017 13:31:23 -0400 Subject: [PATCH] Begin work on Desktop Widgets --- ShiftOS.WinForms/DesktopWidgetAttribute.cs | 21 +++ .../DesktopWidgets/Clock.Designer.cs | 63 +++++++++ ShiftOS.WinForms/DesktopWidgets/Clock.cs | 45 +++++++ ShiftOS.WinForms/DesktopWidgets/Clock.resx | 120 ++++++++++++++++++ ShiftOS.WinForms/IDesktopWidget.cs | 51 ++++++++ ShiftOS.WinForms/Resources/Shiftorium.txt | 11 ++ ShiftOS.WinForms/ShiftOS.WinForms.csproj | 12 ++ ShiftOS.WinForms/WidgetManager.cs | 50 ++++++++ ShiftOS.WinForms/WinformsDesktop.Designer.cs | 48 ++++--- ShiftOS.WinForms/WinformsDesktop.cs | 42 ++++++ 10 files changed, 445 insertions(+), 18 deletions(-) create mode 100644 ShiftOS.WinForms/DesktopWidgetAttribute.cs create mode 100644 ShiftOS.WinForms/DesktopWidgets/Clock.Designer.cs create mode 100644 ShiftOS.WinForms/DesktopWidgets/Clock.cs create mode 100644 ShiftOS.WinForms/DesktopWidgets/Clock.resx create mode 100644 ShiftOS.WinForms/IDesktopWidget.cs create mode 100644 ShiftOS.WinForms/WidgetManager.cs diff --git a/ShiftOS.WinForms/DesktopWidgetAttribute.cs b/ShiftOS.WinForms/DesktopWidgetAttribute.cs new file mode 100644 index 0000000..28d50ac --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgetAttribute.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.WinForms +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class DesktopWidgetAttribute : Attribute + { + public string Name { get; set; } + public string Description { get; set; } + + public DesktopWidgetAttribute(string n, string desc) + { + Name = n; + Description = desc; + } + } +} diff --git a/ShiftOS.WinForms/DesktopWidgets/Clock.Designer.cs b/ShiftOS.WinForms/DesktopWidgets/Clock.Designer.cs new file mode 100644 index 0000000..a36d386 --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/Clock.Designer.cs @@ -0,0 +1,63 @@ +namespace ShiftOS.WinForms.DesktopWidgets +{ + partial class Clock + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lbtime = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lbtime + // + this.lbtime.BackColor = System.Drawing.Color.Transparent; + this.lbtime.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbtime.Location = new System.Drawing.Point(0, 0); + this.lbtime.Name = "lbtime"; + this.lbtime.Size = new System.Drawing.Size(210, 49); + this.lbtime.TabIndex = 0; + this.lbtime.Tag = "header2 keepbg"; + this.lbtime.Text = "label1"; + this.lbtime.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // Clock + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.lbtime); + this.Name = "Clock"; + this.Size = new System.Drawing.Size(210, 49); + this.Tag = "keepbg"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label lbtime; + } +} diff --git a/ShiftOS.WinForms/DesktopWidgets/Clock.cs b/ShiftOS.WinForms/DesktopWidgets/Clock.cs new file mode 100644 index 0000000..aa29e2e --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/Clock.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.DesktopWidgets +{ + [DesktopWidget("Clock", "Show a clock on the desktop.")] + [RequiresUpgrade("desktop_clock_widget")] + public partial class Clock : UserControl, IDesktopWidget + { + public Clock() + { + InitializeComponent(); + tmr = new Timer(); + tmr.Tick += (o, a) => + { + lbtime.Text = Applications.Terminal.GetTime(); + }; + tmr.Interval = 100; + } + + Timer tmr = new Timer(); + + public void OnSkinLoad() + { + Tools.ControlManager.SetupControls(this); + } + + public void OnUpgrade() + { + } + + public void Setup() + { + tmr.Start(); + } + } +} diff --git a/ShiftOS.WinForms/DesktopWidgets/Clock.resx b/ShiftOS.WinForms/DesktopWidgets/Clock.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/Clock.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/IDesktopWidget.cs b/ShiftOS.WinForms/IDesktopWidget.cs new file mode 100644 index 0000000..95c373c --- /dev/null +++ b/ShiftOS.WinForms/IDesktopWidget.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms +{ + /// + /// Provides base functionality for a ShiftOS desktop widget. + /// + public interface IDesktopWidget + { + /// + /// Performs routine setup operations to keep the widget up to date. + /// + void Setup(); + + /// + /// Occurs when a skin is loaded. + /// + void OnSkinLoad(); + + /// + /// Occurs when a Shiftorium upgrade is installed. + /// + void OnUpgrade(); + + /// + /// Hides this desktop widget. + /// + void Hide(); + + /// + /// Shows this desktop widget. + /// + void Show(); + + /// + /// Gets or sets the location on the desktop that this widget resides. + /// + Point Location { get; set; } + + /// + /// Gets or sets this widget's size. + /// + Size Size { get; set; } + } +} diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index 82ee613..c18f456 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -1,4 +1,15 @@ [ + //TEMPORARY + { + Name: "Desktop Widgets", + Cost: 0, + Description: "Temporary upgrade. Will be replaced by either a Shiftnet app or a story element.", + Dependencies: "advanced_app_launcher;wm_free_placement", + Category: "Work-in-progress" + }, + + + // SCREENSAVER { Name: "Screensavers", diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 9675bb6..a223f47 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -257,6 +257,13 @@ Component + + + UserControl + + + Clock.cs + UserControl @@ -271,6 +278,7 @@ + Form @@ -294,6 +302,7 @@ + UserControl @@ -399,6 +408,9 @@ UpdateManager.cs + + Clock.cs + DownloadControl.cs diff --git a/ShiftOS.WinForms/WidgetManager.cs b/ShiftOS.WinForms/WidgetManager.cs new file mode 100644 index 0000000..125c804 --- /dev/null +++ b/ShiftOS.WinForms/WidgetManager.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms +{ + public static class WidgetManager + { + public static Dictionary GetAllWidgetTypes() + { + Dictionary types = new Dictionary(); + foreach(var exe in Directory.GetFiles(Environment.CurrentDirectory)) + { + if(exe.EndsWith(".exe") || exe.EndsWith(".dll")) + { + try + { + var asm = Assembly.LoadFile(exe); + foreach(var type in asm.GetTypes()) + { + if (type.GetInterfaces().Contains(typeof(IDesktopWidget))) + { + if (Shiftorium.UpgradeAttributesUnlocked(type)) + { + foreach (var attrib in type.GetCustomAttributes(false)) + { + if (attrib is DesktopWidgetAttribute) + { + var dw = attrib as DesktopWidgetAttribute; + types.Add(dw, type); + } + } + } + } + } + } + catch { } + } + } + return types; + } + + + } +} diff --git a/ShiftOS.WinForms/WinformsDesktop.Designer.cs b/ShiftOS.WinForms/WinformsDesktop.Designer.cs index 3d24c3d..71ef161 100644 --- a/ShiftOS.WinForms/WinformsDesktop.Designer.cs +++ b/ShiftOS.WinForms/WinformsDesktop.Designer.cs @@ -60,14 +60,15 @@ namespace ShiftOS.WinForms this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.apps = new System.Windows.Forms.ToolStripMenuItem(); this.pnlscreensaver = new System.Windows.Forms.Panel(); + this.pnlwidgetlayer = new System.Windows.Forms.Panel(); this.pnlssicon = new System.Windows.Forms.Panel(); this.pnladvancedal = new System.Windows.Forms.Panel(); + this.flapps = new System.Windows.Forms.FlowLayoutPanel(); + this.flcategories = new System.Windows.Forms.FlowLayoutPanel(); this.pnlalsystemactions = new System.Windows.Forms.Panel(); this.btnshutdown = new System.Windows.Forms.Button(); this.pnlstatus = new System.Windows.Forms.Panel(); this.lbalstatus = new System.Windows.Forms.Label(); - this.flcategories = new System.Windows.Forms.FlowLayoutPanel(); - this.flapps = new System.Windows.Forms.FlowLayoutPanel(); this.desktoppanel.SuspendLayout(); this.sysmenuholder.SuspendLayout(); this.menuStrip1.SuspendLayout(); @@ -169,6 +170,15 @@ namespace ShiftOS.WinForms this.pnlscreensaver.TabIndex = 1; this.pnlscreensaver.Visible = false; // + // pnlwidgetlayer + // + this.pnlwidgetlayer.BackColor = System.Drawing.Color.Transparent; + this.pnlwidgetlayer.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlwidgetlayer.Location = new System.Drawing.Point(0, 24); + this.pnlwidgetlayer.Name = "pnlwidgetlayer"; + this.pnlwidgetlayer.Size = new System.Drawing.Size(1296, 714); + this.pnlwidgetlayer.TabIndex = 1; + // // pnlssicon // this.pnlssicon.Location = new System.Drawing.Point(303, 495); @@ -188,6 +198,22 @@ namespace ShiftOS.WinForms this.pnladvancedal.TabIndex = 1; this.pnladvancedal.Visible = false; // + // flapps + // + this.flapps.Dock = System.Windows.Forms.DockStyle.Fill; + this.flapps.Location = new System.Drawing.Point(221, 58); + this.flapps.Name = "flapps"; + this.flapps.Size = new System.Drawing.Size(212, 328); + this.flapps.TabIndex = 3; + // + // flcategories + // + this.flcategories.Dock = System.Windows.Forms.DockStyle.Left; + this.flcategories.Location = new System.Drawing.Point(0, 58); + this.flcategories.Name = "flcategories"; + this.flcategories.Size = new System.Drawing.Size(221, 328); + this.flcategories.TabIndex = 2; + // // pnlalsystemactions // this.pnlalsystemactions.Controls.Add(this.btnshutdown); @@ -230,28 +256,13 @@ namespace ShiftOS.WinForms this.lbalstatus.Text = "michael@system\r\n0 Codepoints\r\n0 installed, 0 available"; this.lbalstatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // flcategories - // - this.flcategories.Dock = System.Windows.Forms.DockStyle.Left; - this.flcategories.Location = new System.Drawing.Point(0, 58); - this.flcategories.Name = "flcategories"; - this.flcategories.Size = new System.Drawing.Size(221, 328); - this.flcategories.TabIndex = 2; - // - // flapps - // - this.flapps.Dock = System.Windows.Forms.DockStyle.Fill; - this.flapps.Location = new System.Drawing.Point(221, 58); - this.flapps.Name = "flapps"; - this.flapps.Size = new System.Drawing.Size(212, 328); - this.flapps.TabIndex = 3; - // // WinformsDesktop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(1296, 738); + this.Controls.Add(this.pnlwidgetlayer); this.Controls.Add(this.pnladvancedal); this.Controls.Add(this.pnlscreensaver); this.Controls.Add(this.desktoppanel); @@ -294,6 +305,7 @@ namespace ShiftOS.WinForms private System.Windows.Forms.Label lbalstatus; private System.Windows.Forms.FlowLayoutPanel flapps; private System.Windows.Forms.FlowLayoutPanel flcategories; + private System.Windows.Forms.Panel pnlwidgetlayer; } } diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index cd74a6b..3050cdf 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -49,6 +49,9 @@ namespace ShiftOS.WinForms /// public partial class WinformsDesktop : Form, IDesktop { + public List Widgets = new List(); + + private bool InScreensaver = false; private int millisecondsUntilScreensaver = 300000; @@ -65,6 +68,11 @@ namespace ShiftOS.WinForms SetupControl(desktoppanel); Shiftorium.Installed += () => { + foreach(var widget in Widgets) + { + widget.OnUpgrade(); + } + //Only if the DevX Legions story hasn't been experienced yet. if (!Shiftorium.UpgradeInstalled("devx_legions")) { @@ -161,6 +169,11 @@ namespace ShiftOS.WinForms }; SkinEngine.SkinLoaded += () => { + foreach (var widget in Widgets) + { + widget.OnSkinLoad(); + } + SetupDesktop(); }; time.Tick += (o, a) => @@ -429,6 +442,34 @@ namespace ShiftOS.WinForms desktoppanel.Dock = DockStyle.Top; } } + + pnlwidgetlayer.Show(); + pnlwidgetlayer.BringToFront(); + + if (Shiftorium.UpgradeInstalled("desktop_widgets")) + { + Widgets.Clear(); + foreach(var widget in WidgetManager.GetAllWidgetTypes()) + { + UserControl w = (UserControl)Activator.CreateInstance(widget.Value, null); + pnlwidgetlayer.Controls.Add(w); + Widgets.Add(w as IDesktopWidget); + } + } + + foreach (var widget in Widgets) + { + if (Shiftorium.UpgradeInstalled("desktop_widgets")) + { + widget.Setup(); + widget.Show(); + } + else + { + widget.Hide(); + } + } + } else { @@ -851,6 +892,7 @@ namespace ShiftOS.WinForms apps.DropDown.Hide(); pnladvancedal.Location = new Point(0, (LoadedSkin.DesktopPanelPosition == 0) ? desktoppanel.Height : this.Height - pnladvancedal.Height - desktoppanel.Height); pnladvancedal.Visible = !pnladvancedal.Visible; + pnladvancedal.BringToFront(); } }