All pastes #92172 Raw Edit

blip

public text v1 · immutable
#92172 ·published 2006-07-19 09:01 UTC
rendered paste body
using System;
using System.Windows.Forms;

namespace foo_bar
{
	public enum DownloadType { Server, Client };
	public enum SubItemTypes { Progress, State };
	public enum DownloadState { ConnectingToHttp, ConnectingToServer, Running, Paused, TimeOut, Error, Okay, Server };

	class DownloadItem : ListViewItem
	{
		private string[] DownloadStateMessages = new string[7] {"Connecting to the HTTP server", "Connecting to the MetroLeech server", "Running",
														   "Paused", "The download has timed out", "Error downloading the file", 
														   "The download has finished succesfully"};

		// generic properties
		public DownloadType Type;
		public string FileName;
		public bool IsSelected;

		private int progress;
		private DownloadState state;
		private string url;
		private long size;

		// server properties
		public int ClientCount;
		public int FinishedSegments;
		public int DownloadSegments;

		// client properties
		public int Speed;
		public int DownloadedSegments;

		public DownloadItem(DownloadType type, string name)
		{
			// generic properties
			Type = type;
			IsSelected = false;

			// server properties
			ClientCount = 0;
			FinishedSegments = 0;
			DownloadSegments = 0;

			// client properties
			Speed = 0;
			DownloadedSegments = 0;

			// add the subitems
			ListViewItem.ListViewSubItem state = new ListViewItem.ListViewSubItem();

			state.Tag = SubItemTypes.State;
			SubItems.Add(state);

			FileName = name;
			SubItems.Add(FileName);

			ListViewItem.ListViewSubItem progress = new ListViewItem.ListViewSubItem();

			progress.Tag = SubItemTypes.Progress;
			progress.Text = "0";
			SubItems.Add(progress);
		}

		public void SetProgress(int value)
		{
			progress = value;
			SubItems[3].Text = value.ToString();
			ListView.Invalidate();
		}

		public void SetState(DownloadState value)
		{
			state = value;
			SubItems[1].Text = ((int)value).ToString();
			ToolTipText = DownloadStateMessages[(int)value];
			ListView.Invalidate();
		}

		public void SetInfo(string url, long size)
		{
			this.url = url;
			this.size = size;
		}
	}
}