public ShouldStartEventArgs(Download download)
 {
     Download = download;
     ShouldStart = true;
 }
 public StateChangedEventArgs(Download download, State newState, State oldState)
 {
     Download = download;
     OldState = oldState;
     NewState = newState;
 }
        private string GetStatusString(Download manager)
        {
            if (manager == null)
                return "";

            if(manager.State == Monsoon.State.Queued)
                return _("Queued");

            switch (manager.State)
            {
            case Monsoon.State.Stopped:
                return manager.Complete ? "Finished" : "Stopped";
            case Monsoon.State.Seeding:
                return "Seeding";
            case Monsoon.State.Downloading:
                return "Downloading";
            case Monsoon.State.Hashing:
                return "Hashing";
            case Monsoon.State.Paused:
                return "Paused";
            default:
                return manager.State.ToString ();
            }
        }
        void RemoveDownload(Download download)
        {
            TreeIter iter;
            if (Torrents.GetIterFirst (out iter)) {
                do {
                    if (download != Torrents.GetValue (iter, 0))
                        continue;

                    download.PriorityChanged -= HandlePriorityChanged;
                    download.StateChanged -= HandleStateChanged;
                    Torrents.Remove (ref iter);
                    Selection.UnselectAll ();
                    break;
                } while (Torrents.IterNext (ref iter));
            }
        }
        private string GetEtaString(Download manager)
        {
            TimeSpan eta;
            if (manager.State == Monsoon.State.Downloading && (manager.Torrent.Size - manager.TotalDownloaded) > 0)
            {
                double dSpeed = manager.DownloadSpeed;
                eta = TimeSpan.FromSeconds(dSpeed > 0 ? ((manager.Torrent.Size - manager.TotalDownloaded) / dSpeed) : -1);
            }
            else if (manager.State == Monsoon.State.Seeding && (manager.Torrent.Size - manager.TotalUploaded) > 0)
            {
                double uSpeed = manager.UploadSpeed;
                eta = TimeSpan.FromSeconds(uSpeed > 0 ? ((manager.Torrent.Size - manager.TotalUploaded) / uSpeed) : -1);
            }
            else
                return string.Empty;

            if (eta.Seconds <= 0)
                return "∞";
            if (eta.Days > 0)
                return string.Format("{0}d {1}h", eta.Days, eta.Hours);
            if (eta.Hours > 0)
                return string.Format("{0}h {1}m", eta.Hours, eta.Minutes);
            if (eta.Minutes > 0)
                return string.Format("{0}m {1}s", eta.Minutes, eta.Seconds);

            return string.Format("{0}s", eta.Seconds);
        }
        private string GetStatusColour(Download torrent)
        {
            if (torrent.State == Monsoon.State.Downloading)
                return "darkgreen";
            if (torrent.State == Monsoon.State.Paused)
                return "orange";
            if (torrent.State == Monsoon.State.Hashing)
                return "purple";
            if (torrent.State == Monsoon.State.Seeding)
                return "darkgreen";
            if (torrent.State == Monsoon.State.Stopped && torrent.Complete)
                return "blue";
            if (torrent.State == Monsoon.State.Queued)
                return "black";

            return "red";
        }
 void AddDownload(Download download)
 {
     download.StateChanged += HandleStateChanged;
     download.PriorityChanged += HandlePriorityChanged;
     Update (Torrents.AppendValues (download));
 }
 public DownloadAddedEventArgs(Download download)
 {
     Download = download;
 }
        public void SetPriority(Download download, int priority)
        {
            for (int i = 0; i < allTorrents.Count; i++)
                if (allTorrents [i].Priority < download.Priority)
                    allTorrents [i].Priority++;

            for (int i = 0; i < allTorrents.Count; i++)
                if (allTorrents [i].Priority <= priority)
                    allTorrents [i].Priority--;

            download.Priority = priority;

            for (int i = 0; i < allTorrents.Count; i++)
                Console.WriteLine ("{0}: {1}", allTorrents [i].Priority, allTorrents [i].Torrent.Name);
        }
        public Download addTorrent(Torrent torrent, bool startTorrent, bool removeOriginal, TorrentSettings savedSettings, string savePath, bool isUrl)
        {
            string originalPath = torrent.TorrentPath;
            Download manager;

            if(!Directory.Exists(savePath))
                throw new TorrentException("Torrent save path does not exist, " + savePath);

            // Check to see if torrent already exists
            if (engine.Contains (torrent)) {
                logger.Error ("Failed to add torrent, " + torrent.Name + " already exists.");
                throw new TorrentException ("Failed to add torrent, " + torrent.Name + " already exists.");
            }

            // Move the .torrent to the local storage folder if it's not there already
            MoveToStorage (ref torrent);

            TorrentSettings settings = savedSettings ?? defaultTorrentSettings.Clone ();
            FastResume resume = this.fastResume.Find(delegate (FastResume f) { return f.Infohash == torrent.InfoHash; });

            manager = new Download(savePath, new TorrentManager (torrent, savePath, settings));
            if (resume != null)
                manager.Manager.LoadFastResume (resume);

            engine.Register(manager.Manager);

            if (removeOriginal) {
                logger.Info ("Removing {0}", originalPath);
                File.Delete (originalPath);
            }

            Event.Raise<DownloadAddedEventArgs> (Added, this, new DownloadAddedEventArgs (manager));
            allTorrents.Add (manager);

            if (startTorrent) {
                logger.Info("Auto starting torrent " + manager.Torrent.Name);
                manager.Start();
            }

            logger.Info ("Added torrent " + manager.Torrent.Name);

            return manager;
        }
        public void Update(Download download)
        {
            if (this.download == download)
                return;

            this.download = download;
            this.manager = download == null ? null : download.Manager;

            Clear ();
            if (download == null)
                return;

            foreach (TorrentFile torrentFile in manager.Torrent.Files)
                AppendValues(manager, torrentFile, GetPixbuf (torrentFile.Priority), torrentFile.Path);
        }