Winify – Rev 3
?pathlinks?
using System;
using System.ComponentModel;
using System.Configuration;
using System.Windows.Forms;
using AutoUpdaterDotNET;
using Winify.Gotify;
using Winify.Properties;
namespace Winify
{
public partial class Form1 : Form
{
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
private AboutForm _aboutForm;
private GotifyConnection _gotifyConnection;
private NotificationForm _notificationForm;
private SettingsForm _settingsForm;
#endregion
#region Constructors, Destructors and Finalizers
public Form1()
{
InitializeComponent();
AutoUpdater.Start("http://winify.grimore.org/update/winify.xml");
// Upgrade settings if required.
if (!ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).HasFile)
{
Settings.Default.Upgrade();
}
// Bind to settings changed event.
Settings.Default.SettingsLoaded += Default_SettingsLoaded;
Settings.Default.SettingsSaving += Default_SettingsSaving;
Settings.Default.PropertyChanged += Default_PropertyChanged;
Settings.Default.PropertyChanged += Default_PropertyChanged1;
_gotifyConnection = new GotifyConnection();
_gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification;
_gotifyConnection.Start(Settings.Default.Username, Settings.Default.Password, Settings.Default.Host,
Settings.Default.Port);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
_gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification;
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
#region Event Handlers
private void GotifyConnection_GotifyNotification(object sender, GotifyNotificationEventArgs e)
{
_notificationForm = new NotificationForm(e.Image, e.Notification.Title, e.Notification.Message, 5000);
_notificationForm.Show();
}
private void Default_PropertyChanged1(object sender, PropertyChangedEventArgs e)
{
if (_gotifyConnection != null)
{
_gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification;
_gotifyConnection.Stop();
_gotifyConnection.Dispose();
_gotifyConnection = null;
}
_gotifyConnection = new GotifyConnection();
_gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification;
_gotifyConnection.Start(Settings.Default.Username, Settings.Default.Password, Settings.Default.Host,
Settings.Default.Port);
}
private static void Default_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Settings.Default.Save();
}
private static void Default_SettingsSaving(object sender, CancelEventArgs e)
{
}
private static void Default_SettingsLoaded(object sender, SettingsLoadedEventArgs e)
{
}
private void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_settingsForm != null)
{
return;
}
_settingsForm = new SettingsForm();
_settingsForm.Closing += SettingsForm_Closing;
;
_settingsForm.Show();
}
private void SettingsForm_Closing(object sender, CancelEventArgs e)
{
if (_aboutForm == null)
{
return;
}
_settingsForm.Closing -= SettingsForm_Closing;
_settingsForm.Dispose();
_settingsForm = null;
}
private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_aboutForm != null)
{
return;
}
_aboutForm = new AboutForm();
_aboutForm.Closing += AboutForm_Closing;
_aboutForm.Show();
}
private void AboutForm_Closing(object sender, CancelEventArgs e)
{
if (_aboutForm == null)
{
return;
}
_aboutForm.Closing -= AboutForm_Closing;
_aboutForm.Dispose();
_aboutForm = null;
}
private void QuitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
#endregion
}
}
Generated by GNU Enscript 1.6.5.90.