Click here to Skip to main content
15,881,413 members
Articles / Programming Languages / Visual Basic

RSS Feed Aggregator and Blogging Smart Client

Rate me:
Please Sign up or sign in to vote.
4.91/5 (85 votes)
16 Aug 2005CPOL52 min read 1.1M   2.4K   397  
RSS Feed aggregator and blogging Smart Client which uses Enterprise Library, Updater Application Block, lots of XML hacks and desktop tricks. A comprehensive guide to real life hurdles of Smart Client development.
// Copyright � 2005 by Omar Al Zabir. All rights are reserved.
// 
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
// 
// website http://www.oazabir.com, email OmarAlZabir@gmail.com, msn oazabir@hotmail.com

using System;
using System.Text;
using System.Diagnostics;
using System.Drawing;
using System.Xml;
using System.IO;
using System.Xml.Xsl;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace RSSFeeder
{
	using RSSCommon;
	using RSSCommon.Helper;
	using Helpers;
	using RSSBlogAPI;

	/// <summary>
	/// Main Form which shows channels and RSS Feeds in preview window
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		#region Constants

		private const int STARTUP_SHOW_CHANNEL_DURATION = 1000;
		private const int ON_SELECT_SHOW_CHANNEL_DURATION = 300;
		private const int FEED_SELECT_SHOW_DURATION = 1000;
		private const int SEARCH_RESULT_SHOW_INTERVAL = 1000;

		#endregion

		#region Designer
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.StatusBar statusBar;
		private System.Windows.Forms.Panel mainPanel;
		private System.Windows.Forms.Panel leftPanel;
		private System.Windows.Forms.Splitter splitter2;
		private System.Windows.Forms.Panel rightPanel;
		private System.Windows.Forms.Splitter splitter3;
		private System.Windows.Forms.Panel propertiesPanel;
		private System.Windows.Forms.Panel feedPanel;
		private System.Windows.Forms.Panel previewPanel;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Panel panel3;
		private System.Windows.Forms.PropertyGrid channelSetting;
		private System.Windows.Forms.ListView feedsListView;
		private System.Windows.Forms.ColumnHeader titleColumn;
		private System.Windows.Forms.ColumnHeader publishDateColumn;
		private RSSFeeder.DateFilterControl feedFilterDate;
		private System.Windows.Forms.Panel channelActions;
		private System.Windows.Forms.Button downloadAllButton;
		private System.Windows.Forms.Button downloadSelectedButton;
		private System.Windows.Forms.MenuItem exitMenuItem;
		private System.Windows.Forms.MenuItem addNewMenuItem;
		private System.Windows.Forms.MenuItem deleteMenuItem;
		private System.Windows.Forms.MenuItem optionesMenuItem;
		private System.Windows.Forms.MenuItem aboutMenuItem;
		private System.Windows.Forms.Panel panel5;
		private System.Windows.Forms.ListView channelListView;
		private System.Windows.Forms.ColumnHeader channelTitleColumn;
		private System.Windows.Forms.ColumnHeader lastUpdateColumn;
		private System.Windows.Forms.ColumnHeader countColumn;
		private System.Windows.Forms.Label boldLabel;
		private System.Windows.Forms.ContextMenu channelMenu;
		private System.Windows.Forms.MenuItem addNewChannelMenuItem;
		private System.Windows.Forms.MenuItem editMenuItem;
		private System.Windows.Forms.MenuItem deleteChannelMenuItem;
		private System.Windows.Forms.ContextMenu feedContextMenu;
		private System.Windows.Forms.MenuItem markAsReadMenuItem;
		private System.Windows.Forms.MenuItem markAsUnreadMenuItem;
		private System.Windows.Forms.MenuItem deleteFeedMenuItem;
		private System.Timers.Timer callbackTimer;
		private System.Windows.Forms.ImageList iconsImageList;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Panel channelListPanel;
		private System.Windows.Forms.Splitter splitter4;
		private System.Windows.Forms.Panel previewTitlePanel;
		private System.Windows.Forms.Panel previewControlPanel;
		private AxSHDocVw.AxWebBrowser previewControl;
		private System.Windows.Forms.Panel panel6;
		private System.Windows.Forms.LinkLabel readBlogPaperLink;
		private System.Windows.Forms.Panel panel4;
		private System.Windows.Forms.TextBox searchTextBox;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.MenuItem importOPMLMenuItme;
		private System.Windows.Forms.MenuItem exportOPMLMenuItem;
		private System.Windows.Forms.OpenFileDialog openDialog;
		private System.Windows.Forms.SaveFileDialog saveDialog;
		private System.ComponentModel.IContainer components;

		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
			this.statusBar = new System.Windows.Forms.StatusBar();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.mainPanel = new System.Windows.Forms.Panel();
			this.rightPanel = new System.Windows.Forms.Panel();
			this.splitter4 = new System.Windows.Forms.Splitter();
			this.previewPanel = new System.Windows.Forms.Panel();
			this.previewControlPanel = new System.Windows.Forms.Panel();
			this.previewControl = new AxSHDocVw.AxWebBrowser();
			this.previewTitlePanel = new System.Windows.Forms.Panel();
			this.label4 = new System.Windows.Forms.Label();
			this.iconsImageList = new System.Windows.Forms.ImageList(this.components);
			this.feedPanel = new System.Windows.Forms.Panel();
			this.panel4 = new System.Windows.Forms.Panel();
			this.searchTextBox = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.panel6 = new System.Windows.Forms.Panel();
			this.readBlogPaperLink = new System.Windows.Forms.LinkLabel();
			this.boldLabel = new System.Windows.Forms.Label();
			this.feedsListView = new System.Windows.Forms.ListView();
			this.titleColumn = new System.Windows.Forms.ColumnHeader();
			this.publishDateColumn = new System.Windows.Forms.ColumnHeader();
			this.feedContextMenu = new System.Windows.Forms.ContextMenu();
			this.markAsReadMenuItem = new System.Windows.Forms.MenuItem();
			this.markAsUnreadMenuItem = new System.Windows.Forms.MenuItem();
			this.deleteFeedMenuItem = new System.Windows.Forms.MenuItem();
			this.panel3 = new System.Windows.Forms.Panel();
			this.label3 = new System.Windows.Forms.Label();
			this.feedFilterDate = new RSSFeeder.DateFilterControl();
			this.splitter2 = new System.Windows.Forms.Splitter();
			this.leftPanel = new System.Windows.Forms.Panel();
			this.propertiesPanel = new System.Windows.Forms.Panel();
			this.channelSetting = new System.Windows.Forms.PropertyGrid();
			this.panel2 = new System.Windows.Forms.Panel();
			this.label2 = new System.Windows.Forms.Label();
			this.splitter3 = new System.Windows.Forms.Splitter();
			this.channelListPanel = new System.Windows.Forms.Panel();
			this.panel5 = new System.Windows.Forms.Panel();
			this.channelListView = new System.Windows.Forms.ListView();
			this.channelTitleColumn = new System.Windows.Forms.ColumnHeader();
			this.countColumn = new System.Windows.Forms.ColumnHeader();
			this.lastUpdateColumn = new System.Windows.Forms.ColumnHeader();
			this.channelMenu = new System.Windows.Forms.ContextMenu();
			this.addNewChannelMenuItem = new System.Windows.Forms.MenuItem();
			this.editMenuItem = new System.Windows.Forms.MenuItem();
			this.deleteChannelMenuItem = new System.Windows.Forms.MenuItem();
			this.channelActions = new System.Windows.Forms.Panel();
			this.downloadAllButton = new System.Windows.Forms.Button();
			this.downloadSelectedButton = new System.Windows.Forms.Button();
			this.panel1 = new System.Windows.Forms.Panel();
			this.label1 = new System.Windows.Forms.Label();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.exitMenuItem = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.addNewMenuItem = new System.Windows.Forms.MenuItem();
			this.deleteMenuItem = new System.Windows.Forms.MenuItem();
			this.importOPMLMenuItme = new System.Windows.Forms.MenuItem();
			this.exportOPMLMenuItem = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.optionesMenuItem = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.aboutMenuItem = new System.Windows.Forms.MenuItem();
			this.callbackTimer = new System.Timers.Timer();
			this.openDialog = new System.Windows.Forms.OpenFileDialog();
			this.saveDialog = new System.Windows.Forms.SaveFileDialog();
			this.mainPanel.SuspendLayout();
			this.rightPanel.SuspendLayout();
			this.previewPanel.SuspendLayout();
			this.previewControlPanel.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.previewControl)).BeginInit();
			this.previewTitlePanel.SuspendLayout();
			this.feedPanel.SuspendLayout();
			this.panel4.SuspendLayout();
			this.panel6.SuspendLayout();
			this.panel3.SuspendLayout();
			this.leftPanel.SuspendLayout();
			this.propertiesPanel.SuspendLayout();
			this.panel2.SuspendLayout();
			this.channelListPanel.SuspendLayout();
			this.panel5.SuspendLayout();
			this.channelActions.SuspendLayout();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.callbackTimer)).BeginInit();
			this.SuspendLayout();
			// 
			// statusBar
			// 
			this.statusBar.Location = new System.Drawing.Point(0, 480);
			this.statusBar.Name = "statusBar";
			this.statusBar.Size = new System.Drawing.Size(824, 22);
			this.statusBar.TabIndex = 0;
			this.statusBar.Text = "Ready.";
			// 
			// splitter1
			// 
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter1.Enabled = false;
			this.splitter1.Location = new System.Drawing.Point(0, 477);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(824, 3);
			this.splitter1.TabIndex = 1;
			this.splitter1.TabStop = false;
			// 
			// mainPanel
			// 
			this.mainPanel.Controls.Add(this.rightPanel);
			this.mainPanel.Controls.Add(this.splitter2);
			this.mainPanel.Controls.Add(this.leftPanel);
			this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
			this.mainPanel.Location = new System.Drawing.Point(0, 0);
			this.mainPanel.Name = "mainPanel";
			this.mainPanel.Size = new System.Drawing.Size(824, 477);
			this.mainPanel.TabIndex = 2;
			// 
			// rightPanel
			// 
			this.rightPanel.Controls.Add(this.splitter4);
			this.rightPanel.Controls.Add(this.previewPanel);
			this.rightPanel.Controls.Add(this.feedPanel);
			this.rightPanel.Dock = System.Windows.Forms.DockStyle.Fill;
			this.rightPanel.Location = new System.Drawing.Point(203, 0);
			this.rightPanel.Name = "rightPanel";
			this.rightPanel.Size = new System.Drawing.Size(621, 477);
			this.rightPanel.TabIndex = 2;
			// 
			// splitter4
			// 
			this.splitter4.Location = new System.Drawing.Point(288, 0);
			this.splitter4.Name = "splitter4";
			this.splitter4.Size = new System.Drawing.Size(3, 477);
			this.splitter4.TabIndex = 3;
			this.splitter4.TabStop = false;
			// 
			// previewPanel
			// 
			this.previewPanel.BackColor = System.Drawing.Color.White;
			this.previewPanel.Controls.Add(this.previewControlPanel);
			this.previewPanel.Controls.Add(this.previewTitlePanel);
			this.previewPanel.Dock = System.Windows.Forms.DockStyle.Fill;
			this.previewPanel.Location = new System.Drawing.Point(288, 0);
			this.previewPanel.Name = "previewPanel";
			this.previewPanel.Size = new System.Drawing.Size(333, 477);
			this.previewPanel.TabIndex = 2;
			// 
			// previewControlPanel
			// 
			this.previewControlPanel.Controls.Add(this.previewControl);
			this.previewControlPanel.Dock = System.Windows.Forms.DockStyle.Fill;
			this.previewControlPanel.Location = new System.Drawing.Point(0, 24);
			this.previewControlPanel.Name = "previewControlPanel";
			this.previewControlPanel.Size = new System.Drawing.Size(333, 453);
			this.previewControlPanel.TabIndex = 5;
			// 
			// previewControl
			// 
			this.previewControl.ContainingControl = this;
			this.previewControl.Dock = System.Windows.Forms.DockStyle.Fill;
			this.previewControl.Enabled = true;
			this.previewControl.Location = new System.Drawing.Point(0, 0);
			this.previewControl.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("previewControl.OcxState")));
			this.previewControl.Size = new System.Drawing.Size(333, 453);
			this.previewControl.TabIndex = 0;
			this.previewControl.BeforeNavigate2 += new AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.previewControl_BeforeNavigate2);
			// 
			// previewTitlePanel
			// 
			this.previewTitlePanel.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("previewTitlePanel.BackgroundImage")));
			this.previewTitlePanel.Controls.Add(this.label4);
			this.previewTitlePanel.Dock = System.Windows.Forms.DockStyle.Top;
			this.previewTitlePanel.Location = new System.Drawing.Point(0, 0);
			this.previewTitlePanel.Name = "previewTitlePanel";
			this.previewTitlePanel.Size = new System.Drawing.Size(333, 24);
			this.previewTitlePanel.TabIndex = 4;
			// 
			// label4
			// 
			this.label4.BackColor = System.Drawing.Color.Transparent;
			this.label4.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label4.ImageIndex = 14;
			this.label4.ImageList = this.iconsImageList;
			this.label4.Location = new System.Drawing.Point(5, 0);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 24);
			this.label4.TabIndex = 1;
			this.label4.Text = "Preview";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// iconsImageList
			// 
			this.iconsImageList.ImageSize = new System.Drawing.Size(16, 16);
			this.iconsImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("iconsImageList.ImageStream")));
			this.iconsImageList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// feedPanel
			// 
			this.feedPanel.Controls.Add(this.panel4);
			this.feedPanel.Controls.Add(this.panel6);
			this.feedPanel.Controls.Add(this.boldLabel);
			this.feedPanel.Controls.Add(this.feedsListView);
			this.feedPanel.Controls.Add(this.panel3);
			this.feedPanel.Dock = System.Windows.Forms.DockStyle.Left;
			this.feedPanel.Location = new System.Drawing.Point(0, 0);
			this.feedPanel.Name = "feedPanel";
			this.feedPanel.Size = new System.Drawing.Size(288, 477);
			this.feedPanel.TabIndex = 0;
			// 
			// panel4
			// 
			this.panel4.Controls.Add(this.searchTextBox);
			this.panel4.Controls.Add(this.label5);
			this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel4.Location = new System.Drawing.Point(0, 429);
			this.panel4.Name = "panel4";
			this.panel4.Size = new System.Drawing.Size(288, 24);
			this.panel4.TabIndex = 10;
			// 
			// searchTextBox
			// 
			this.searchTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.searchTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
			this.searchTextBox.Location = new System.Drawing.Point(48, 0);
			this.searchTextBox.Name = "searchTextBox";
			this.searchTextBox.Size = new System.Drawing.Size(240, 21);
			this.searchTextBox.TabIndex = 5;
			this.searchTextBox.Text = "";
			this.searchTextBox.TextChanged += new System.EventHandler(this.searchTextBox_TextChanged);
			// 
			// label5
			// 
			this.label5.Dock = System.Windows.Forms.DockStyle.Left;
			this.label5.Location = new System.Drawing.Point(0, 0);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(48, 24);
			this.label5.TabIndex = 4;
			this.label5.Text = "Search:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// panel6
			// 
			this.panel6.Controls.Add(this.readBlogPaperLink);
			this.panel6.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel6.Location = new System.Drawing.Point(0, 453);
			this.panel6.Name = "panel6";
			this.panel6.Size = new System.Drawing.Size(288, 24);
			this.panel6.TabIndex = 9;
			// 
			// readBlogPaperLink
			// 
			this.readBlogPaperLink.Dock = System.Windows.Forms.DockStyle.Left;
			this.readBlogPaperLink.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.readBlogPaperLink.ImageIndex = 14;
			this.readBlogPaperLink.ImageList = this.iconsImageList;
			this.readBlogPaperLink.Location = new System.Drawing.Point(0, 0);
			this.readBlogPaperLink.Name = "readBlogPaperLink";
			this.readBlogPaperLink.Size = new System.Drawing.Size(144, 24);
			this.readBlogPaperLink.TabIndex = 4;
			this.readBlogPaperLink.TabStop = true;
			this.readBlogPaperLink.Text = "Read in Blogpaper";
			this.readBlogPaperLink.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.readBlogPaperLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.readBlogPaperLink_LinkClicked);
			// 
			// boldLabel
			// 
			this.boldLabel.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.boldLabel.Location = new System.Drawing.Point(8, 32);
			this.boldLabel.Name = "boldLabel";
			this.boldLabel.TabIndex = 6;
			this.boldLabel.Text = "label5";
			this.boldLabel.Visible = false;
			// 
			// feedsListView
			// 
			this.feedsListView.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.feedsListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																							this.titleColumn,
																							this.publishDateColumn});
			this.feedsListView.ContextMenu = this.feedContextMenu;
			this.feedsListView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.feedsListView.ForeColor = System.Drawing.Color.DimGray;
			this.feedsListView.FullRowSelect = true;
			this.feedsListView.GridLines = true;
			this.feedsListView.HideSelection = false;
			this.feedsListView.Location = new System.Drawing.Point(0, 24);
			this.feedsListView.Name = "feedsListView";
			this.feedsListView.Size = new System.Drawing.Size(288, 453);
			this.feedsListView.SmallImageList = this.iconsImageList;
			this.feedsListView.TabIndex = 5;
			this.feedsListView.View = System.Windows.Forms.View.Details;
			this.feedsListView.KeyUp += new System.Windows.Forms.KeyEventHandler(this.feedsListView_KeyUp);
			this.feedsListView.SelectedIndexChanged += new System.EventHandler(this.feedsListView_SelectedIndexChanged);
			// 
			// titleColumn
			// 
			this.titleColumn.Text = "Title";
			this.titleColumn.Width = 200;
			// 
			// publishDateColumn
			// 
			this.publishDateColumn.Text = "Publish Date";
			this.publishDateColumn.Width = 100;
			// 
			// feedContextMenu
			// 
			this.feedContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							this.markAsReadMenuItem,
																							this.markAsUnreadMenuItem,
																							this.deleteFeedMenuItem});
			// 
			// markAsReadMenuItem
			// 
			this.markAsReadMenuItem.Index = 0;
			this.markAsReadMenuItem.Text = "Mark as &Read";
			this.markAsReadMenuItem.Click += new System.EventHandler(this.markAsReadMenuItem_Click);
			// 
			// markAsUnreadMenuItem
			// 
			this.markAsUnreadMenuItem.Index = 1;
			this.markAsUnreadMenuItem.Text = "Mark as &Unread";
			this.markAsUnreadMenuItem.Click += new System.EventHandler(this.markAsUnreadMenuItem_Click);
			// 
			// deleteFeedMenuItem
			// 
			this.deleteFeedMenuItem.Index = 2;
			this.deleteFeedMenuItem.Text = "&Delete";
			this.deleteFeedMenuItem.Click += new System.EventHandler(this.deleteFeedMenuItem_Click);
			// 
			// panel3
			// 
			this.panel3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel3.BackgroundImage")));
			this.panel3.Controls.Add(this.label3);
			this.panel3.Controls.Add(this.feedFilterDate);
			this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel3.Location = new System.Drawing.Point(0, 0);
			this.panel3.Name = "panel3";
			this.panel3.Size = new System.Drawing.Size(288, 24);
			this.panel3.TabIndex = 4;
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.Color.Transparent;
			this.label3.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label3.ImageIndex = 13;
			this.label3.ImageList = this.iconsImageList;
			this.label3.Location = new System.Drawing.Point(0, 0);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 24);
			this.label3.TabIndex = 3;
			this.label3.Text = "Posts";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// feedFilterDate
			// 
			this.feedFilterDate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.feedFilterDate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.feedFilterDate.Location = new System.Drawing.Point(171, 0);
			this.feedFilterDate.Name = "feedFilterDate";
			this.feedFilterDate.Size = new System.Drawing.Size(112, 21);
			this.feedFilterDate.TabIndex = 1;
			this.feedFilterDate.SelectedIndexChanged += new System.EventHandler(this.feedFilterDate_SelectedIndexChanged);
			// 
			// splitter2
			// 
			this.splitter2.Location = new System.Drawing.Point(200, 0);
			this.splitter2.Name = "splitter2";
			this.splitter2.Size = new System.Drawing.Size(3, 477);
			this.splitter2.TabIndex = 1;
			this.splitter2.TabStop = false;
			// 
			// leftPanel
			// 
			this.leftPanel.Controls.Add(this.propertiesPanel);
			this.leftPanel.Controls.Add(this.splitter3);
			this.leftPanel.Controls.Add(this.channelListPanel);
			this.leftPanel.Dock = System.Windows.Forms.DockStyle.Left;
			this.leftPanel.Location = new System.Drawing.Point(0, 0);
			this.leftPanel.Name = "leftPanel";
			this.leftPanel.Size = new System.Drawing.Size(200, 477);
			this.leftPanel.TabIndex = 0;
			// 
			// propertiesPanel
			// 
			this.propertiesPanel.BackColor = System.Drawing.Color.White;
			this.propertiesPanel.Controls.Add(this.channelSetting);
			this.propertiesPanel.Controls.Add(this.panel2);
			this.propertiesPanel.Dock = System.Windows.Forms.DockStyle.Fill;
			this.propertiesPanel.Location = new System.Drawing.Point(0, 451);
			this.propertiesPanel.Name = "propertiesPanel";
			this.propertiesPanel.Size = new System.Drawing.Size(200, 26);
			this.propertiesPanel.TabIndex = 2;
			// 
			// channelSetting
			// 
			this.channelSetting.CommandsBackColor = System.Drawing.Color.White;
			this.channelSetting.CommandsVisibleIfAvailable = true;
			this.channelSetting.Dock = System.Windows.Forms.DockStyle.Fill;
			this.channelSetting.LargeButtons = false;
			this.channelSetting.LineColor = System.Drawing.SystemColors.ScrollBar;
			this.channelSetting.Location = new System.Drawing.Point(0, 24);
			this.channelSetting.Name = "channelSetting";
			this.channelSetting.Size = new System.Drawing.Size(200, 2);
			this.channelSetting.TabIndex = 5;
			this.channelSetting.Text = "propertyGrid1";
			this.channelSetting.ToolbarVisible = false;
			this.channelSetting.ViewBackColor = System.Drawing.SystemColors.Window;
			this.channelSetting.ViewForeColor = System.Drawing.SystemColors.WindowText;
			this.channelSetting.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.channelSetting_PropertyValueChanged);
			// 
			// panel2
			// 
			this.panel2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel2.BackgroundImage")));
			this.panel2.Controls.Add(this.label2);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel2.Location = new System.Drawing.Point(0, 0);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(200, 24);
			this.panel2.TabIndex = 4;
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.Cursor = System.Windows.Forms.Cursors.Hand;
			this.label2.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label2.ImageIndex = 6;
			this.label2.ImageList = this.iconsImageList;
			this.label2.Location = new System.Drawing.Point(0, 0);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(96, 24);
			this.label2.TabIndex = 0;
			this.label2.Text = "Properties";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label2.Click += new System.EventHandler(this.editMenuItem_Click);
			// 
			// splitter3
			// 
			this.splitter3.Dock = System.Windows.Forms.DockStyle.Top;
			this.splitter3.Location = new System.Drawing.Point(0, 448);
			this.splitter3.Name = "splitter3";
			this.splitter3.Size = new System.Drawing.Size(200, 3);
			this.splitter3.TabIndex = 1;
			this.splitter3.TabStop = false;
			// 
			// channelListPanel
			// 
			this.channelListPanel.Controls.Add(this.panel5);
			this.channelListPanel.Controls.Add(this.channelActions);
			this.channelListPanel.Controls.Add(this.panel1);
			this.channelListPanel.Dock = System.Windows.Forms.DockStyle.Top;
			this.channelListPanel.Location = new System.Drawing.Point(0, 0);
			this.channelListPanel.Name = "channelListPanel";
			this.channelListPanel.Size = new System.Drawing.Size(200, 448);
			this.channelListPanel.TabIndex = 0;
			// 
			// panel5
			// 
			this.panel5.Controls.Add(this.channelListView);
			this.panel5.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel5.Location = new System.Drawing.Point(0, 24);
			this.panel5.Name = "panel5";
			this.panel5.Size = new System.Drawing.Size(200, 392);
			this.panel5.TabIndex = 6;
			// 
			// channelListView
			// 
			this.channelListView.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.channelListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																							  this.channelTitleColumn,
																							  this.countColumn,
																							  this.lastUpdateColumn});
			this.channelListView.ContextMenu = this.channelMenu;
			this.channelListView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.channelListView.ForeColor = System.Drawing.Color.DimGray;
			this.channelListView.FullRowSelect = true;
			this.channelListView.GridLines = true;
			this.channelListView.HideSelection = false;
			this.channelListView.Location = new System.Drawing.Point(0, 0);
			this.channelListView.Name = "channelListView";
			this.channelListView.Size = new System.Drawing.Size(200, 392);
			this.channelListView.SmallImageList = this.iconsImageList;
			this.channelListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
			this.channelListView.TabIndex = 5;
			this.channelListView.View = System.Windows.Forms.View.Details;
			this.channelListView.KeyUp += new System.Windows.Forms.KeyEventHandler(this.channelListView_KeyUp);
			this.channelListView.SelectedIndexChanged += new System.EventHandler(this.channelListView_SelectedIndexChanged);
			// 
			// channelTitleColumn
			// 
			this.channelTitleColumn.Text = "Title";
			this.channelTitleColumn.Width = 160;
			// 
			// countColumn
			// 
			this.countColumn.Text = "No.";
			this.countColumn.Width = 40;
			// 
			// lastUpdateColumn
			// 
			this.lastUpdateColumn.Text = "Last Update";
			this.lastUpdateColumn.Width = 100;
			// 
			// channelMenu
			// 
			this.channelMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						this.addNewChannelMenuItem,
																						this.editMenuItem,
																						this.deleteChannelMenuItem});
			// 
			// addNewChannelMenuItem
			// 
			this.addNewChannelMenuItem.Index = 0;
			this.addNewChannelMenuItem.Text = "&Add New Channel...";
			this.addNewChannelMenuItem.Click += new System.EventHandler(this.addNewMenuItem_Click);
			// 
			// editMenuItem
			// 
			this.editMenuItem.Index = 1;
			this.editMenuItem.Text = "&Edit";
			this.editMenuItem.Click += new System.EventHandler(this.editMenuItem_Click);
			// 
			// deleteChannelMenuItem
			// 
			this.deleteChannelMenuItem.Index = 2;
			this.deleteChannelMenuItem.Text = "&Delete";
			this.deleteChannelMenuItem.Click += new System.EventHandler(this.deleteMenuItem_Click);
			// 
			// channelActions
			// 
			this.channelActions.BackColor = System.Drawing.SystemColors.Control;
			this.channelActions.Controls.Add(this.downloadAllButton);
			this.channelActions.Controls.Add(this.downloadSelectedButton);
			this.channelActions.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.channelActions.Location = new System.Drawing.Point(0, 416);
			this.channelActions.Name = "channelActions";
			this.channelActions.Size = new System.Drawing.Size(200, 32);
			this.channelActions.TabIndex = 5;
			// 
			// downloadAllButton
			// 
			this.downloadAllButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.downloadAllButton.ImageIndex = 11;
			this.downloadAllButton.ImageList = this.iconsImageList;
			this.downloadAllButton.Location = new System.Drawing.Point(104, 0);
			this.downloadAllButton.Name = "downloadAllButton";
			this.downloadAllButton.Size = new System.Drawing.Size(96, 32);
			this.downloadAllButton.TabIndex = 1;
			this.downloadAllButton.Text = "Download All";
			this.downloadAllButton.Click += new System.EventHandler(this.downloadAllButton_Click);
			// 
			// downloadSelectedButton
			// 
			this.downloadSelectedButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.downloadSelectedButton.ImageIndex = 11;
			this.downloadSelectedButton.ImageList = this.iconsImageList;
			this.downloadSelectedButton.Location = new System.Drawing.Point(0, 0);
			this.downloadSelectedButton.Name = "downloadSelectedButton";
			this.downloadSelectedButton.Size = new System.Drawing.Size(104, 32);
			this.downloadSelectedButton.TabIndex = 0;
			this.downloadSelectedButton.Text = "Download Selected";
			this.downloadSelectedButton.Click += new System.EventHandler(this.downloadSelectedButton_Click);
			// 
			// panel1
			// 
			this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));
			this.panel1.Controls.Add(this.label1);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(200, 24);
			this.panel1.TabIndex = 3;
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label1.ImageIndex = 12;
			this.label1.ImageList = this.iconsImageList;
			this.label1.Location = new System.Drawing.Point(0, 0);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(112, 24);
			this.label1.TabIndex = 1;
			this.label1.Text = "Subscription";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1,
																					  this.menuItem2,
																					  this.menuItem3,
																					  this.menuItem4});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.exitMenuItem});
			this.menuItem1.Text = "&File";
			// 
			// exitMenuItem
			// 
			this.exitMenuItem.Index = 0;
			this.exitMenuItem.Text = "E&xit";
			this.exitMenuItem.Click += new System.EventHandler(this.exitMenuItem_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.addNewMenuItem,
																					  this.deleteMenuItem,
																					  this.importOPMLMenuItme,
																					  this.exportOPMLMenuItem});
			this.menuItem2.Text = "&Channels";
			// 
			// addNewMenuItem
			// 
			this.addNewMenuItem.Index = 0;
			this.addNewMenuItem.Text = "&Add New RSS Feed source...";
			this.addNewMenuItem.Click += new System.EventHandler(this.addNewMenuItem_Click);
			// 
			// deleteMenuItem
			// 
			this.deleteMenuItem.Index = 1;
			this.deleteMenuItem.Text = "&Delete selected Channels";
			this.deleteMenuItem.Click += new System.EventHandler(this.deleteMenuItem_Click);
			// 
			// importOPMLMenuItme
			// 
			this.importOPMLMenuItme.Index = 2;
			this.importOPMLMenuItme.Text = "&Import Channels from OPML...";
			this.importOPMLMenuItme.Click += new System.EventHandler(this.importOPMLMenuItme_Click);
			// 
			// exportOPMLMenuItem
			// 
			this.exportOPMLMenuItem.Index = 3;
			this.exportOPMLMenuItem.Text = "&Export selected Channels to OPML...";
			this.exportOPMLMenuItem.Click += new System.EventHandler(this.exportOPMLMenuItem_Click);
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 2;
			this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.optionesMenuItem});
			this.menuItem3.Text = "&Tools";
			// 
			// optionesMenuItem
			// 
			this.optionesMenuItem.Index = 0;
			this.optionesMenuItem.Text = "&Options";
			this.optionesMenuItem.Click += new System.EventHandler(this.optionesMenuItem_Click);
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 3;
			this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.aboutMenuItem});
			this.menuItem4.Text = "&Help";
			// 
			// aboutMenuItem
			// 
			this.aboutMenuItem.Index = 0;
			this.aboutMenuItem.Text = "&About";
			this.aboutMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);
			// 
			// callbackTimer
			// 
			this.callbackTimer.Interval = 1000;
			this.callbackTimer.SynchronizingObject = this;
			this.callbackTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.callbackTimer_Elapsed);
			// 
			// MainForm
			// 
			this.AllowDrop = true;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(824, 502);
			this.Controls.Add(this.mainPanel);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.statusBar);
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mainMenu1;
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "RSS Feeder";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
			this.Load += new System.EventHandler(this.MainForm_Load);
			this.DragDrop += new System.Windows.Forms.DragEventHandler(this.MainForm_DragDrop);
			this.DragEnter += new System.Windows.Forms.DragEventHandler(this.MainForm_DragEnter);
			this.Deactivate += new System.EventHandler(this.MainForm_Deactivate);
			this.mainPanel.ResumeLayout(false);
			this.rightPanel.ResumeLayout(false);
			this.previewPanel.ResumeLayout(false);
			this.previewControlPanel.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.previewControl)).EndInit();
			this.previewTitlePanel.ResumeLayout(false);
			this.feedPanel.ResumeLayout(false);
			this.panel4.ResumeLayout(false);
			this.panel6.ResumeLayout(false);
			this.panel3.ResumeLayout(false);
			this.leftPanel.ResumeLayout(false);
			this.propertiesPanel.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			this.channelListPanel.ResumeLayout(false);
			this.panel5.ResumeLayout(false);
			this.channelActions.ResumeLayout(false);
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.callbackTimer)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#endregion

		#region Private Methods

		private MethodInvoker _CallbackMethod = null;

		//private WebLogMenuHelper _WebLogMenuHelper;
		/// <summary>
		/// Load all channels from database and populate the channel list view
		/// </summary>
		private void LoadChannels()
		{
			this.RefreshChannels();

			//this._WebLogMenuHelper = new WebLogMenuHelper( this.webLogMenu, this );
			//this._WebLogMenuHelper.RefreshWebLogMenu();
			//if( channelListView.Items.Count > 0 )
			//	channelListView.Items[0].Selected = true;
		}
		
		private ListViewItem AddChannelInListView( Channel channel )
		{
			ListViewItem item = new ListViewItem( new string[] { channel.Title, channel.UnreadCount.ToString(), channel.LastUpdated.ToString() }, 10 );
			item.Tag = channel;
			channelListView.Items.Add( item );
			
			if( channel.UnreadCount > 0 )
				item.Font = boldLabel.Font;
			else
				item.Font = base.Font;

			return item;
		}

		/// <summary>
		/// Show channel properties of the selected channels.
		/// </summary>
		private void UpdateChannelProperties()
		{
			channelSetting.SelectedObjects = this.GetSelectedChannels().ToArray();
		}

		/// <summary>
		/// Prepare a list of selected channels from the channel list view
		/// </summary>
		/// <returns></returns>
		private ArrayList GetSelectedChannels()
		{
			ArrayList list = new ArrayList();

			foreach( ListViewItem item in channelListView.SelectedItems )
			{
				list.Add( item.Tag );
			}

			return list;
		}

		/// <summary>
		/// Delete selected channel(s) from database, permanently
		/// </summary>
		private void DeleteChannel()
		{
			if( DialogResult.No == MessageBox.Show( this, 
				"Are you sure you want to delete the selected channels?", 
				"Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ) )
				return;

			// Delete selected channels
			foreach( Channel channel in this.GetSelectedChannels() )
			{
				DatabaseHelper.DeleteChannel( channel.Id );
			}

			// Refresh the list
			this.RefreshChannels();
		}

		/// <summary>
		/// Show feeds from selected channel
		/// </summary>
		private void ShowFeeds()
		{
			if( 0 == channelListView.SelectedItems.Count )
			{
				feedsListView.Items.Clear();
				return;
			}
			
			// Get the first selected channel
			Channel channel = (Channel)channelListView.SelectedItems[0].Tag;

			// Load rss feeds
			DateTime dateAfter = feedFilterDate.SelectedItem.DateTime;
			IList feeds = DatabaseHelper.GetRssItems( channel.Id, dateAfter );

			this.ShowFeeds( feeds );			
		}

		/// <summary>
		/// Show the specified collection of feed in feed list
		/// </summary>
		/// <param name="feeds"></param>
		private void ShowFeeds( IList feeds )
		{
			// populate the rss feed list view
			feedsListView.Items.Clear();
			foreach( RssFeed feed in feeds )
			{
				ListViewItem item = new ListViewItem( new string [] { feed.Title, feed.PublishDate.ToString() }, 9 );
				item.Tag = feed;

				if( !feed.IsRead ) item.Font = boldLabel.Font;

				feedsListView.Items.Add( item );
			}

			if( 0 < feedsListView.Items.Count )
			{
				feedsListView.Items[0].Selected = true;
			}
		}

		/// <summary>
		/// Return an RssFeed object collection of the selected posts in the post list view
		/// </summary>
		/// <returns></returns>
		private ArrayList GetSelectedPosts()
		{
			ArrayList posts = new ArrayList();
			foreach( ListViewItem item in feedsListView.SelectedItems )
			{
				posts.Add( item.Tag );
			}
			return posts;
		}

		/// <summary>
		/// Preview currently selected item
		/// </summary>
		private void ViewPreview()
		{
			ArrayList posts = this.GetSelectedPosts();
			if( 0 == posts.Count ) return;

			// Show the last item in the selection
			RssFeed feed = posts[ posts.Count-1 ] as RssFeed;

			// change the font of the current item
			feedsListView.SelectedItems[ feedsListView.SelectedItems.Count - 1 ].Font = base.Font;

			this.ShowFeed( feed );
		}

		private Channel GetChannel( int channelID )
		{
			foreach( ListViewItem item in this.channelListView.Items )
			{
				Channel channel = item.Tag as Channel;
				if( channel.Id == channelID )
					return channel;
			}

			return null;
		}
		/// <summary>
		/// Shwo a feed in the preview pane
		/// </summary>
		/// <param name="feed"></param>
		private void ShowFeed( RssFeed feed )
		{
			// Get the XSLT for transforming
			Channel channel = this.GetChannel(feed.ChannelID);
			if( null == channel ) return;

			string xsltFile = channel.XSLPath;

			// If none specified in the channel, look in the global setting
			if( null == xsltFile || 0 == xsltFile.Length ) xsltFile = Configuration.Instance.XSLFileName;

			string tempFilePath = Path.Combine( ApplicationSettings.ApplicationDataPath, "Preview.html" );

			// Generate a temporary HTML file for preview
			FileStream file = new FileStream( tempFilePath, FileMode.Create );
			//XMLHelper.GenerateXMLForChannel( xsltFile, feed.XML, file );
			XMLHelper.TransformXml( xsltFile, feed.XML, file );
			file.Close();

			// Show preview of the post
			this.ShowUrl( tempFilePath );

			DatabaseHelper.MarkAsRead( true, feed.Guid, feed.ChannelID, false );
			
			// Make refresh channel as due
			this._CallbackMethod = new MethodInvoker( this.RecalculateAndRefresh );
			callbackTimer.Stop();
			callbackTimer.Interval = FEED_SELECT_SHOW_DURATION;
			callbackTimer.Start();
		}
		/// <summary>
		/// Shows the specified URL in a browser control
		/// </summary>
		/// <param name="url"></param>
		private void ShowUrl( object url )
		{
			object nil = System.Reflection.Missing.Value;			
			previewControl.Navigate2( ref url, ref nil, ref nil, ref nil, ref nil );
			
			#region Old Code
			/*
			AxSHDocVw.AxWebBrowser previewControl = this.EnsureBrowserControl();
			
			object nil = System.Reflection.Missing.Value;
			object flags = BrowserNavConstants.navNoReadFromCache | BrowserNavConstants.navNoWriteToCache;
			object blank = "about:blank";
			
			try
			{
				//previewControl.Navigate2( ref blank );
				previewControl.Navigate2( ref url, ref flags, ref nil, ref nil, ref nil );
			}
			catch( Exception x )
			{
				Debug.WriteLine( x );
				EntLibHelper.Exception( "Preview", x );
			}
			*/
			#endregion
		}
		
		#region Old Code
		/*
		/// <summary>
		/// Creates a browser control is not already shown
		/// </summary>
		/// <returns></returns>
		private AxSHDocVw.AxWebBrowser EnsureBrowserControl()
		{
			foreach( Control c in previewPanel.Controls )
			{
				if( c is AxSHDocVw.AxWebBrowser )
					return c as AxSHDocVw.AxWebBrowser;
			}

			previewPanel.SuspendLayout();
			
			AxSHDocVw.AxWebBrowser browser = new AxSHDocVw.AxWebBrowser();
			//browser.BeforeNavigate2 += new AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(previewControl_BeforeNavigate2);
			browser.AllowDrop = false;
			browser.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(previewControl_NewWindow3);
			browser.Dock = DockStyle.Fill;
			browser.Visible = true;
			previewControlPanel.Controls.Add( browser );

			previewControlPanel.ResumeLayout();

			return browser;
		}*/
		#endregion

		/// <summary>
		/// Get the selected chanel in list view. If there is multiple selection, the 
		/// first item is returned
		/// </summary>
		/// <returns></returns>
		private Channel GetCurrentlySelecetdChannel()
		{
			if( 0 == channelListView.SelectedItems.Count ) return null;
			return (Channel)channelListView.SelectedItems[0].Tag;
		}

		private void RecalculateAndRefresh()
		{
			Channel channel = this.GetCurrentlySelecetdChannel();
			if( null == channel ) return;
			
			// Recalculate item count of this channel
			DatabaseHelper.RefreshChannelCounts( channel.Id );
			
			// Refresh list view
			this.RefreshChannels();
		}

		/// <summary>
		/// Download selected channels
		/// </summary>
		private void DownloadSelectedChannels()
		{
			IList channels = this.GetSelectedChannels();
			RSSHelper.DownloadChannels( this, channels, new EventHandler( this.DownloadComplete ) );
		}

		/// <summary>
		/// Download all channels
		/// </summary>
		private void DownloadAllChannels()
		{
			ArrayList channels = new ArrayList();
			foreach( ListViewItem item in this.channelListView.Items )
			{
				channels.Add( item.Tag );
			}

			RSSHelper.DownloadChannels( this, channels, new EventHandler( this.DownloadComplete ) );
		}

		private void DownloadComplete( object sender, EventArgs e )
		{
			// Refresh channel list
			this.RefreshChannels();

			// Show currently selected channel feeds
			this.ShowFeeds();
		}
		/// <summary>
		/// Show the Global Options dialog
		/// </summary>
		private void ShowOptions()
		{
			PropertyView form = new PropertyView();
			
			form.SelectedObject = Configuration.Instance;

			base.AddOwnedForm( form );
			form.Show( );
		
			form.Closing += new CancelEventHandler(form_Closing);
		}

		/// <summary>
		/// Show About Dialog
		/// </summary>
		private void ShowAbout()
		{
			using( AboutForm form = new AboutForm() )
			{
				form.ShowDialog( this );
			}
		}

		private void MarkSelectedItems( bool isRead )
		{
			// 1. Get selected feeds
			IList feeds = this.GetSelectedPosts();

			if( 0 == feeds.Count ) return;

			// 2. Mark as read
			int channelId = 0;
			foreach( RssFeed feed in feeds )
			{
				channelId = feed.ChannelID;
				DatabaseHelper.MarkAsRead( isRead, feed.Guid, feed.ChannelID, false );
			}

			DatabaseHelper.RefreshChannelCounts( channelId );

			// 3. Change post font
			feedsListView.BeginUpdate();
			foreach( ListViewItem item in feedsListView.SelectedItems )
			{
				item.Font = boldLabel.Font;
			}
			feedsListView.EndUpdate();

			// 4. Refresh channel list
			this.RefreshChannels();
		}

		private void DeleteSelectedItems()
		{
			// 1. Get selected feeds
			IList feeds = this.GetSelectedPosts();

			if( 0 == feeds.Count ) return;

			// 2. Delete feed
			int channelId = 0;
			foreach( RssFeed feed in feeds )
			{
				channelId = feed.ChannelID;
				DatabaseHelper.DeleteFeed( feed.Guid, feed.ChannelID, false );
			}

			DatabaseHelper.RefreshChannelCounts( channelId );

			// 3. Remove items from list view
			feedsListView.BeginUpdate();
			foreach( ListViewItem item in feedsListView.SelectedItems )
			{
				feedsListView.Items.Remove( item );
			}
			feedsListView.EndUpdate();

			// 4. Refresh channel list
			this.RefreshChannels();
		}

		private void RefreshChannels()
		{
			// 1. Get recent channel list
			IList channels = DatabaseHelper.GetChannels();
			IList deletedChannels = new ArrayList();

			// 2. Update status in list view
			foreach( ListViewItem item in channelListView.Items )
			{
				bool isFound = false;
				foreach( Channel channel in channels )
				{
					Channel channelInListView = item.Tag as Channel;

					if( channelInListView.Id == channel.Id )
					{
						isFound = true;

						// Update list view item texts
						this.UpdateChannelInListView( item, channel );

						break;
					}
				}

				if( !isFound )
				{
					// Delete the channel from list view
					deletedChannels.Add( item );
				}
			}

			// 3. Delete the removed channels
			foreach( ListViewItem item in deletedChannels )
			{
				channelListView.Items.Remove( item );
			}

			// 4. If is any channel was added in the meantime but not in list
			foreach( Channel channel in channels )
			{
				bool isFound = false;
				foreach( ListViewItem item in channelListView.Items )
				{
					Channel channelInListView = item.Tag as Channel;

					if( channelInListView.Id == channel.Id )
					{
						isFound = true;
						break;
					}
				}

				if( !isFound )
				{
					// Add new channel
					channelListView.SelectedItems.Clear();
					ListViewItem newItem = this.AddChannelInListView( channel );
					newItem.Selected = true;
					newItem.EnsureVisible();
				}
			}

		}

		/// <summary>
		/// Refresh the list view item with current channel information
		/// </summary>
		/// <param name="item"></param>
		/// <param name="channel"></param>
		private void UpdateChannelInListView( ListViewItem item, Channel channel )
		{
			item.Text = channel.Title;
			item.SubItems[1].Text = channel.UnreadCount.ToString();
			item.SubItems[2].Text = channel.LastUpdated.ToString();

			item.Tag = channel;

			if( channel.UnreadCount > 0 )
				item.Font = boldLabel.Font;
			else
				item.Font = base.Font;
		}

		/// <summary>
		/// Update the currently selected channels
		/// </summary>
		private void UpdateChannel()
		{
			IList channels = this.GetSelectedChannels();
			if( 0 == channels.Count ) return;

			foreach( Channel channel in channels )
				DatabaseHelper.UpdateChannel( channel );

			this.RefreshChannels();
		}
		
		private void AutoSelectChannel()
		{
			int channelId = (int)this.Tag;

			foreach( ListViewItem item in channelListView.Items )
			{
				Channel channelInListView = item.Tag as Channel;
				if( channelInListView.Id == channelId )
				{
					channelListView.SelectedItems.Clear();
					item.Selected = true;

					break;
				}																	
			}
		}

		private void ShowNewspaperView()
		{
			Channel channel = this.GetCurrentlySelecetdChannel();
			if( null == channel ) return;

			EntryPoint.ShowNewspaper( channel.Id );

			this.Close();
		}

		private void AddNewChannel( string url )
		{
			using( AddNewChannel form = new AddNewChannel() )
			{
				form.Url = url;
				form.OnDownloadComplete = new EventHandler(this.DownloadComplete);
				if( DialogResult.OK == form.ShowDialog( this ) )
					this.RefreshChannels();
			}
		}
		
		private void DeliverPendingPosts()
		{
			RSSHelper.DownloadChannels( this, new ArrayList(), new EventHandler( DownloadComplete ) );
		}
	
		private void SearchFeed( string text )
		{
			IList feeds = DatabaseHelper.SearchFeed( text.Trim() );
			this.ShowFeeds( feeds );
		}

		private void ImportOPML()
		{
			openDialog.Filter = "OPML (*.opml)|*.opml";
			if( DialogResult.OK == openDialog.ShowDialog( this ) )
			{
				IList importedChannels = OPMLHelper.ImportOPML( openDialog.FileName );

				StringBuilder message = new StringBuilder();

				foreach( Channel channel in importedChannels )
				{
					message.Append( channel.Title );
					message.Append( Environment.NewLine );
				}

				MessageBox.Show( this, "Imported Channles: " + Environment.NewLine + message,
					"Import OPML", MessageBoxButtons.OK, MessageBoxIcon.Information );
				
				this.RefreshChannels();
			}

		}

		private void ExportOPML()
		{
			saveDialog.Filter = "OPML (*.opml)|*.opml";
			if( DialogResult.OK == saveDialog.ShowDialog( this ) )
			{
				IList selectedChannels = this.GetSelectedChannels();

				OPMLHelper.ExportOPML( selectedChannels, saveDialog.FileName );

				MessageBox.Show( this, "OPML Exported complete." , "OPML Export", 
					MessageBoxButtons.OK, MessageBoxIcon.Information );
			}
		}

		private void ShowCurrentChannel()
		{
			this.UpdateChannelProperties();
			this.ShowFeeds();
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// Preselct a channel to show after load
		/// </summary>
		/// <param name="channelId"></param>
		public void ShowChannel( int channelId )
		{
			// Store the channel ID somewhere so that after a while we can get it
			this.Tag = channelId;

			// Make a callback method to call after a while to auto select the channel in list view
			this._CallbackMethod = new MethodInvoker( this.AutoSelectChannel );
			this.callbackTimer.Interval = STARTUP_SHOW_CHANNEL_DURATION;
			this.callbackTimer.Start();
		}

		#endregion

		#region Control Events

		private void MainForm_Load(object sender, System.EventArgs e)
		{
			// Restore window position
			if( Rectangle.Empty != Configuration.Instance.WindowBounds )
			{
				base.Bounds = Configuration.Instance.WindowBounds;
				base.WindowState = (FormWindowState)Configuration.Instance.WindowState;
			}

			this.LoadChannels();

			object url = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "docs\\Welcome.html" );
			this.ShowUrl( url );
		}

		private void channelListView_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this._CallbackMethod = new MethodInvoker( this.ShowCurrentChannel );
			this.callbackTimer.Interval = ON_SELECT_SHOW_CHANNEL_DURATION;
			this.callbackTimer.Start();
		}

		private void feedsListView_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.ViewPreview();
		}

		private void downloadSelectedButton_Click(object sender, System.EventArgs e)
		{
			this.DownloadSelectedChannels();
		}

		private void downloadAllButton_Click(object sender, System.EventArgs e)
		{
			this.DownloadAllChannels();
		}

		private void feedFilterDate_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.ShowFeeds();
		}

		private void exitMenuItem_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void addNewMenuItem_Click(object sender, System.EventArgs e)
		{
			this.AddNewChannel( string.Empty );
		}

		private void deleteMenuItem_Click(object sender, System.EventArgs e)
		{
			this.DeleteChannel();
		}

		private void optionesMenuItem_Click(object sender, System.EventArgs e)
		{
			this.ShowOptions();
		}

		private void aboutMenuItem_Click(object sender, System.EventArgs e)
		{
			this.ShowAbout();
		}

		private void editMenuItem_Click(object sender, System.EventArgs e)
		{
			this.channelSetting.Focus();
			this.channelListPanel.Height = this.leftPanel.Height/2;
		}

		private void markAsReadMenuItem_Click(object sender, System.EventArgs e)
		{
			this.MarkSelectedItems( true );
		}

		private void markAsUnreadMenuItem_Click(object sender, System.EventArgs e)
		{
			this.MarkSelectedItems( false );
		}

		private void deleteFeedMenuItem_Click(object sender, System.EventArgs e)
		{
			this.DeleteSelectedItems();
		}

		private void callbackTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
		{
			callbackTimer.Stop();

			if( null != this._CallbackMethod )
				this._CallbackMethod();

			this._CallbackMethod = null;
			
		}

		private void channelSetting_PropertyValueChanged(object s, System.Windows.Forms.PropertyValueChangedEventArgs e)
		{
			this.UpdateChannel();
		}

		private void readBlogPaperLink_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			this.ShowNewspaperView();
		}

		private void previewControl_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
		{			
			// User has probably dragged a page or RSS to the browser. So, let's try adding a channel from it
			string url = e.uRL as string;
			if( null == url ) return;
			
			if( BrowserHelper.IsURLFile( url ) || url == "about:blank" ) 
			{				
				return;
			}
			else
			{
				e.cancel = true;
				// User has dragged an URL to this browser, perform RSS discovery
				//this.AddNewChannel( e.uRL as string );
				BrowserHelper.BrowseURL( url );
			}
		}

		private void previewControl_NewWindow3(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow3Event e)
		{
			e.cancel = BrowserHelper.BrowseURL( e.bstrUrl );
		}

		
		private void form_Closing(object sender, CancelEventArgs e)
		{
			(sender as Form).Closing -= new CancelEventHandler(form_Closing);
			base.Activate();
		}

		private void MainForm_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
		{
			BrowserHelper.DragEnter( e );
		}

		private void MainForm_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
		{
			string hyperLinkUrl = BrowserHelper.GetDroppedURL( e );
			if( null == hyperLinkUrl || 0 == hyperLinkUrl.Length )
				return;

			this.AddNewChannel( hyperLinkUrl );
			
		}

		private void MainForm_Deactivate(object sender, System.EventArgs e)
		{
			MemoryHelper.ReduceMemory();
		}

		private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if( base.WindowState == FormWindowState.Normal )
				Configuration.Instance.WindowBounds = base.Bounds;

			if( base.WindowState != FormWindowState.Minimized )
				Configuration.Instance.WindowState = (int)base.WindowState;
		}

//		private void addNewWebLogMenuItem_Click(object sender, System.EventArgs e)
//		{
//			this._WebLogMenuHelper.NewWebLog();
//		}

		
		private void deliverPendingPostsMenuItem_Click(object sender, System.EventArgs e)
		{
			this.DeliverPendingPosts();
		}

		private void searchTextBox_TextChanged(object sender, System.EventArgs e)
		{
			this._CallbackMethod = new MethodInvoker(this.Search);
			this.callbackTimer.Stop();
			this.callbackTimer.Interval = SEARCH_RESULT_SHOW_INTERVAL;
			this.callbackTimer.Start();
		}

		private void Search()
		{
			base.Cursor = Cursors.AppStarting;
			base.Refresh();

			this.SearchFeed( searchTextBox.Text );

			base.Cursor = Cursors.Default;
		}
		
		private void importOPMLMenuItme_Click(object sender, System.EventArgs e)
		{
			this.ImportOPML();
		}

		private void exportOPMLMenuItem_Click(object sender, System.EventArgs e)
		{
			this.ExportOPML();
		}

		
		private void channelListView_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if( e.KeyCode == Keys.Delete )
				this.deleteMenuItem_Click( sender, e );
		}

		private void feedsListView_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if( e.KeyCode == Keys.Delete )
				this.deleteFeedMenuItem_Click( sender, e );
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions