GUI/PortForm.cs
changeset 348 d8fa1e55acfa
child 358 7962499f9cd6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/GUI/PortForm.cs	Sun May 27 20:15:32 2012 +0000
     1.3 @@ -0,0 +1,77 @@
     1.4 +/*
     1.5 + 
     1.6 +  This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +  License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +  file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 + 
    1.10 +	Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
    1.11 +
    1.12 +*/
    1.13 +
    1.14 +using System;
    1.15 +using System.Collections.Generic;
    1.16 +using System.ComponentModel;
    1.17 +using System.Data;
    1.18 +using System.Drawing;
    1.19 +using System.Text;
    1.20 +using System.Windows.Forms;
    1.21 +using System.Net;
    1.22 +using System.Net.Sockets;
    1.23 +using System.Diagnostics;
    1.24 +
    1.25 +namespace OpenHardwareMonitor.GUI {
    1.26 +  public partial class PortForm : Form {
    1.27 +    private MainForm parent;
    1.28 +    private string localIP;
    1.29 +    public PortForm(MainForm m) {
    1.30 +      InitializeComponent();
    1.31 +      parent = m;
    1.32 +
    1.33 +      localIP = getLocalIP();
    1.34 +    }
    1.35 +
    1.36 +    private void portTextBox_TextChanged(object sender, EventArgs e) {
    1.37 +
    1.38 +    }
    1.39 +
    1.40 +    private string getLocalIP() {
    1.41 +      IPHostEntry host;
    1.42 +      string localIP = "?";
    1.43 +      host = Dns.GetHostEntry(Dns.GetHostName());
    1.44 +      foreach (IPAddress ip in host.AddressList) {
    1.45 +        if (ip.AddressFamily == AddressFamily.InterNetwork) {
    1.46 +          localIP = ip.ToString();
    1.47 +        }
    1.48 +      }
    1.49 +      return localIP;
    1.50 +    }
    1.51 +
    1.52 +    private void portNumericUpDn_ValueChanged(object sender, EventArgs e) {
    1.53 +      string url = "http://" + localIP + ":" + portNumericUpDn.Value + "/";
    1.54 +      webServerLinkLabel.Text = url;
    1.55 +      webServerLinkLabel.Links.Remove(webServerLinkLabel.Links[0]);
    1.56 +      webServerLinkLabel.Links.Add(0, webServerLinkLabel.Text.Length, url);
    1.57 +    }
    1.58 +
    1.59 +    private void portOKButton_Click(object sender, EventArgs e) {
    1.60 +      parent.Server.ListenerPort = (int)portNumericUpDn.Value;
    1.61 +      this.Close();
    1.62 +    }
    1.63 +
    1.64 +    private void portCancelButton_Click(object sender, EventArgs e) {
    1.65 +      this.Close();
    1.66 +    }
    1.67 +
    1.68 +    private void PortForm_Load(object sender, EventArgs e) {
    1.69 +      portNumericUpDn.Value = parent.Server.ListenerPort;
    1.70 +      portNumericUpDn_ValueChanged(null, null);
    1.71 +    }
    1.72 +
    1.73 +    private void webServerLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
    1.74 +      try {
    1.75 +        Process.Start(new ProcessStartInfo(e.Link.LinkData.ToString()));
    1.76 +      } catch { }
    1.77 +    }
    1.78 +
    1.79 +  }
    1.80 +}