public MainWindow (): base (Gtk.WindowType.Toplevel)
	{
		if (!BlinkstickDeviceFinder.IsUnix())
		{
			SetupSingleInstanceEvent();
		}

		Build ();

		this.Title = "BlinkStick " + ApplicationVersion;

		log.Debug("Setting up controls");

		Gtk.TreeViewColumn eventTitleColumn = new Gtk.TreeViewColumn ();
		eventTitleColumn.Title = "Name";

		Gtk.TreeViewColumn eventTypeColumn = new Gtk.TreeViewColumn ();
		eventTypeColumn.Title = "Type";

		Gtk.TreeViewColumn eventColorColumn = new Gtk.TreeViewColumn ();
		eventColorColumn.Title = "Color";

		// Create the text cell that will display the artist name
		Gtk.CellRendererText eventTitleCell = new Gtk.CellRendererText ();
		Gtk.CellRendererText eventTypeCell = new Gtk.CellRendererText ();
		Gtk.CellRendererPixbuf eventColorCell = new Gtk.CellRendererPixbuf ();

		log.Debug ("Loading main form icon");
		this.Icon = new global::Gdk.Pixbuf (global::System.IO.Path.Combine (global::System.AppDomain.CurrentDomain.BaseDirectory, "icon.png"));
			 
		log.Debug( "Setting up treeview");
		// Add the cell to the column
		eventColorColumn.PackStart (eventColorCell, false);
		eventTypeColumn.PackEnd (eventTypeCell, true);
		eventTitleColumn.PackEnd (eventTitleCell, true);
	 
		// Tell the Cell Renderers which items in the model to display
		//eventTitleColumn.AddAttribute (eventTitleCell, "name", 0);
		eventTitleColumn.SetCellDataFunc (eventTitleCell, new Gtk.TreeCellDataFunc (RenderEventName));
		eventTypeColumn.SetCellDataFunc (eventTypeCell, new Gtk.TreeCellDataFunc (RenderEventType));
		eventColorColumn.SetCellDataFunc (eventColorCell, new Gtk.TreeCellDataFunc (RenderEventColor));

		treeviewEvents.Model = EventListStore;

		treeviewEvents.AppendColumn (eventColorColumn);
		treeviewEvents.AppendColumn (eventTypeColumn);
		treeviewEvents.AppendColumn (eventTitleColumn);

		log.Debug("Updating buttons");
		UpdateButtons ();

		log.Debug("Setting up notification manager");
		Manager = new NotificationManager ();
		Manager.NotificationUpdated += HandleNotificationUpdated;
		Manager.Load ();
		Manager.UpdateControllers();

		DeviceMonitor = new UsbMonitor(this.GdkWindow.Handle);
		DeviceMonitor.UsbDeviceAdded += (object sender, EventArgs e) => {
			Gtk.Application.Invoke (delegate {
				Manager.UpdateControllers();

				if (testForm != null)
				{
					testForm.PopulateForm();
				}
			});
		};
		DeviceMonitor.Start ();

		log.Debug("Adding notifications to the tree");
		//Gtk.TreeIter customEventRoot = EventListStore.AppendValues(new TriggeredEvent("Custom"));
		foreach (CustomNotification e in Manager.Notifications) {
			//EventListStore.AppendValues(customEventRoot, e);
			EventListStore.AppendValues (e);
		}

		log.Debug("Starting notification manager");
		Manager.Start ();

		log.Debug ("Building popup menu");
		//Build Popup Menu for TrayIcon
		popupMenu = new Menu ();

		//Settings menu item
		ImageMenuItem menuItemSettings = new ImageMenuItem ("Settings");
		menuItemSettings.Image = new Gtk.Image(Stock.Preferences, IconSize.Menu);
		menuItemSettings.Activated += ToggleMainWindow;
		popupMenu.Append(menuItemSettings);

		popupMenu.Append(new SeparatorMenuItem());

		//Quit menu item
		ImageMenuItem menuItemQuit = new ImageMenuItem ("Quit");
		menuItemQuit.Image = new Gtk.Image (Stock.Quit, IconSize.Menu);
		menuItemQuit.Activated += OnQuitActionActivated;
		popupMenu.Append (menuItemQuit);

		log.Debug("Showing popup menu");
		popupMenu.ShowAll();

#if LINUX
		indicator = new ApplicationIndicator ("blinkstick", "icon", Category.ApplicationStatus, ExecutableFolder);	
		indicator.Menu = popupMenu;
		indicator.Status = AppIndicator.Status.Active;	
#else

		log.Debug ("Setting up tray icon");
		trayIcon = new StatusIcon (new Pixbuf (System.IO.Path.Combine(ExecutableFolder, "icon.ico")));
		trayIcon.Tooltip = this.Title;
		trayIcon.Visible = true;

		// Show/Hide the window (even from the Panel/Taskbar) when the TrayIcon has been clicked.
		trayIcon.Activate += ToggleMainWindow;

		trayIcon.PopupMenu += delegate {
			popupMenu.ShowAll ();
			popupMenu.Popup ();
		};
#endif
		log.Debug("Initialization done");
	}