moel@348: /* moel@348: moel@348: This Source Code Form is subject to the terms of the Mozilla Public moel@348: License, v. 2.0. If a copy of the MPL was not distributed with this moel@348: file, You can obtain one at http://mozilla.org/MPL/2.0/. moel@348: moel@348: Copyright (C) 2012 Prince Samuel moel@348: moel@348: */ moel@348: moel@348: using System; moel@348: using System.Collections.Generic; moel@348: using System.ComponentModel; moel@348: using System.Drawing; moel@348: using System.Text; moel@348: using System.Windows.Forms; moel@348: using System.Net; moel@348: using System.Net.Sockets; moel@348: using System.Diagnostics; moel@348: moel@348: namespace OpenHardwareMonitor.GUI { moel@348: public partial class PortForm : Form { moel@348: private MainForm parent; moel@348: private string localIP; moel@348: public PortForm(MainForm m) { moel@348: InitializeComponent(); moel@348: parent = m; moel@348: moel@348: localIP = getLocalIP(); moel@348: } moel@348: moel@348: private void portTextBox_TextChanged(object sender, EventArgs e) { moel@348: moel@348: } moel@348: moel@348: private string getLocalIP() { moel@348: IPHostEntry host; moel@348: string localIP = "?"; moel@348: host = Dns.GetHostEntry(Dns.GetHostName()); moel@348: foreach (IPAddress ip in host.AddressList) { moel@348: if (ip.AddressFamily == AddressFamily.InterNetwork) { moel@348: localIP = ip.ToString(); moel@348: } moel@348: } moel@348: return localIP; moel@348: } moel@348: moel@348: private void portNumericUpDn_ValueChanged(object sender, EventArgs e) { moel@348: string url = "http://" + localIP + ":" + portNumericUpDn.Value + "/"; moel@348: webServerLinkLabel.Text = url; moel@348: webServerLinkLabel.Links.Remove(webServerLinkLabel.Links[0]); moel@348: webServerLinkLabel.Links.Add(0, webServerLinkLabel.Text.Length, url); moel@348: } moel@348: moel@348: private void portOKButton_Click(object sender, EventArgs e) { moel@348: parent.Server.ListenerPort = (int)portNumericUpDn.Value; moel@348: this.Close(); moel@348: } moel@348: moel@348: private void portCancelButton_Click(object sender, EventArgs e) { moel@348: this.Close(); moel@348: } moel@348: moel@348: private void PortForm_Load(object sender, EventArgs e) { moel@348: portNumericUpDn.Value = parent.Server.ListenerPort; moel@348: portNumericUpDn_ValueChanged(null, null); moel@348: } moel@348: moel@348: private void webServerLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { moel@348: try { moel@348: Process.Start(new ProcessStartInfo(e.Link.LinkData.ToString())); moel@348: } catch { } moel@348: } moel@348: moel@348: } moel@348: }