Beispiel #1
0
        void DhtChanged(object sender, ExtensionNodeEventArgs e)
        {
            try {
                TorrentController controller = ServiceManager.Get <TorrentController> ();
                if (e.Change == ExtensionChange.Add)
                {
                    TypeExtensionNode node = (TypeExtensionNode)e.ExtensionNode;
                    IDhtExtension     dht  = (IDhtExtension)node.GetInstance();
                    if (dht.State == MonoTorrent.DhtState.NotReady)
                    {
                        dht.Start();
                    }

                    controller.Engine.RegisterDht(dht);
                    ToolItem w = dht.GetWidget();
                    if (w != null)
                    {
                        mainWindow.StatusToolbar.Insert(new SeparatorToolItem {
                            Draw         = false,
                            WidthRequest = 10
                        }, 0);
                        mainWindow.StatusToolbar.Insert(w, 0);

                        mainWindow.StatusToolbar.ShowAll();
                    }
                    logger.Info("DHT has been enabled");
                }
                else
                {
                    logger.Warn("DHT cannot be disabled on the fly");
                }
            } catch (Exception ex) {
                logger.Error("Failed to enable DHT: {0}", ex.Message);
            }
        }
        public CreateTorrentDialog(TorrentController torrentController)
        {
            this.Build();
            this.torrentController = torrentController;

            newTorrentLocationButton = new FileChooserButton(_("Select file"), FileChooserAction.Open);

            selectFileHbox.Add(newTorrentLocationButton);
            newTorrentLocationButton.Show();

            BuildTrackerWidgets();
        }
        public CreateTorrentDialog(TorrentController torrentController)
        {
            this.Build();
            this.torrentController = torrentController;

            newTorrentLocationButton = new FileChooserButton(_("Select file"), FileChooserAction.Open);

            selectFileHbox.Add(newTorrentLocationButton);
            newTorrentLocationButton.Show();

            BuildTrackerWidgets();
        }
        public TorrentContextMenu()
        {
            this.torrentController = ServiceManager.Get <TorrentController> ();

            ImageMenuItem openItem = new ImageMenuItem(_("Open"));

            startItem = new ImageMenuItem(_("Start/Pause"));
            stopItem  = new ImageMenuItem(_("Stop"));
            ImageMenuItem removeItem  = new ImageMenuItem(_("Remove"));
            ImageMenuItem deleteItem  = new ImageMenuItem(_("Delete"));
            ImageMenuItem recheckItem = new ImageMenuItem(_("Force Re-_check"));
            //ImageMenuItem hashItem  = new ImageMenuItem(_("Force Re-_hash"));
            ImageMenuItem announceItem = new ImageMenuItem(_("Force _announce"));

            openItem.Image    = new Image(Stock.Open, IconSize.Menu);
            startItem.Image   = new Image(Stock.MediaPlay, IconSize.Menu);
            stopItem.Image    = new Image(Stock.MediaStop, IconSize.Menu);
            removeItem.Image  = new Image(Stock.Remove, IconSize.Menu);
            deleteItem.Image  = new Image(Stock.Delete, IconSize.Menu);
            recheckItem.Image = new Image(Stock.Refresh, IconSize.Menu);
            //hashItem.Image = new Image(Stock.Convert, IconSize.Menu);
            announceItem.Image = new Image(Stock.Network, IconSize.Menu);

            openItem.Activated  += OnOpenItemActivated;
            startItem.Activated += OnStartItemActivated;
            stopItem.Activated  += OnStopItemActivated;

            removeItem.Activated += Event.Wrap((EventHandler) delegate {
                torrentController.RemoveTorrent(true, false);
            });

            deleteItem.Activated += Event.Wrap((EventHandler) delegate {
                torrentController.RemoveTorrent(true, true);
            });
            recheckItem.Activated += OnRecheckItemActivated;
            //hashItem.Activated += OnHashItemActivated;
            announceItem.Activated += OnAnnounceItemActivated;

            Append(openItem);
            Append(new SeparatorMenuItem());
            Append(startItem);
            Append(stopItem);
            Append(removeItem);
            Append(deleteItem);
            Append(new SeparatorMenuItem());
            Append(recheckItem);
            //Append(hashItem);
            Append(announceItem);
        }
//		public int MaxSeeds {
//			get; set;
//		}

        public DownloadQueueService()
        {
            TorrentController c = ServiceManager.Get <TorrentController> ();

            c.Added += delegate(object sender, DownloadAddedEventArgs e) {
                e.Download.ShouldStart     += HandleShouldStart;
                e.Download.StateChanged    += HandleStateChanged;
                e.Download.PriorityChanged += HandlePriorityChanged;;
            };
            c.Removed += delegate(object sender, DownloadAddedEventArgs e) {
                e.Download.ShouldStart     -= HandleShouldStart;
                e.Download.StateChanged    -= HandleStateChanged;
                e.Download.PriorityChanged -= HandlePriorityChanged;
            };
        }
        void ReviewDownloads()
        {
            TorrentController controller = ServiceManager.Get <TorrentController> ();
            List <Download>   downloads  = new List <Download>(controller.Torrents);

            downloads.Sort((left, right) => left.Priority.CompareTo(right.Priority));

            // Try to start the torrents without stopping any existing ones
            while (Toolbox.Count <Download>(downloads, d => d.Active) < MaxDownloads)
            {
                bool started = false;
                for (int i = 0; i < downloads.Count && !started; i++)
                {
                    if (downloads[i].Queued)
                    {
                        downloads[i].Start();
                        started = true;
                    }
                }

                if (!started)
                {
                    break;
                }
            }

            //if (Toolbox.Count <Download>(downloads, d => d.Active) <= MaxActiveDownloads)
            //	return;

            // Ensure that the highest priority downloads are active
            for (int i = 0; i < downloads.Count; i++)
            {
                if (downloads [i].Queued)
                {
                    for (int j = downloads.Count - 1; j > i; j--)
                    {
                        Console.WriteLine("\t Checking: {0}", downloads [j]);
                        if (downloads[j].Active)
                        {
                            Console.WriteLine("\t\tStopping: {0}", downloads[j]);
                            downloads[j].Queue();
                            downloads[i].Start();
                            break;
                        }
                    }
                }
            }
        }
        public TorrentContextMenu()
        {
            this.torrentController = ServiceManager.Get <TorrentController> ();

            ImageMenuItem openItem = new ImageMenuItem(_("Open"));
            startItem = new ImageMenuItem(_("Start/Pause"));
            stopItem  = new ImageMenuItem(_("Stop"));
            ImageMenuItem removeItem  = new ImageMenuItem(_("Remove"));
            ImageMenuItem deleteItem  = new ImageMenuItem(_("Delete"));
            ImageMenuItem recheckItem  = new ImageMenuItem(_("Force Re-_check"));
            //ImageMenuItem hashItem  = new ImageMenuItem(_("Force Re-_hash"));
            ImageMenuItem announceItem  = new ImageMenuItem(_("Force _announce"));

            openItem.Image = new Image(Stock.Open, IconSize.Menu);
            startItem.Image = new Image(Stock.MediaPlay, IconSize.Menu);
            stopItem.Image = new Image(Stock.MediaStop, IconSize.Menu);
            removeItem.Image = new Image(Stock.Remove, IconSize.Menu);
            deleteItem.Image = new Image(Stock.Delete, IconSize.Menu);
            recheckItem.Image = new Image(Stock.Refresh, IconSize.Menu);
            //hashItem.Image = new Image(Stock.Convert, IconSize.Menu);
            announceItem.Image = new Image(Stock.Network, IconSize.Menu);

            openItem.Activated += OnOpenItemActivated;
            startItem.Activated += OnStartItemActivated;
            stopItem.Activated += OnStopItemActivated;

            removeItem.Activated += Event.Wrap ((EventHandler) delegate {
                torrentController.RemoveTorrent (true, false);
            });

            deleteItem.Activated += Event.Wrap ((EventHandler) delegate {
                torrentController.RemoveTorrent (true, true);
            });
            recheckItem.Activated += OnRecheckItemActivated;
            //hashItem.Activated += OnHashItemActivated;
            announceItem.Activated += OnAnnounceItemActivated;

            Append(openItem);
            Append(new SeparatorMenuItem());
            Append(startItem);
            Append(stopItem);
            Append(removeItem);
            Append(deleteItem);
            Append(new SeparatorMenuItem());
            Append(recheckItem);
            //Append(hashItem);
            Append(announceItem);
        }
        void HandleShouldStart(object sender, ShouldStartEventArgs e)
        {
            if (MaxDownloads <= 0)
            {
                return;
            }

            TorrentController c = ServiceManager.Get <TorrentController> ();
            int count           = 0;

            c.Torrents.ForEach(delegate(Download d) {
                if (d.Manager.State == TorrentState.Downloading)
                {
                    count++;
                }
            });

            if (count >= MaxDownloads)
            {
                e.ShouldStart = false;
                e.Download.Queue();
            }
        }
Beispiel #9
0
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            this.portController = ServiceManager.Get <ListenPortController> ();
            this.torrentController = ServiceManager.Get <TorrentController> ();
            interfaceSettings = new InterfaceSettings ();

            Ticker.Tick ();
            LoadAllSettings ();
            Ticker.Tock ("Loaded all settings: {0}");

            Ticker.Tick ();
            Ticker.Tick ();

            Build ();

            AddInManagerAction.Activated += AddInManagerActionActivated;

            InitNatStatus ();

            Ticker.Tock ("Build");
            Ticker.Tick();
            BuildStatusBar();
            Ticker.Tock ("Status bar");
            Ticker.Tick ();
            BuildTray();
            Ticker.Tock ("Tray");
            Ticker.Tick ();
            BuildPiecesTreeView();
            Ticker.Tock ("PiecesTreeview");
            Ticker.Tick ();
            BuildTorrentTreeView();
            Ticker.Tock ("TorrentTreeview");
            Ticker.Tick ();
            BuildPeerTreeView();
            Ticker.Tock ("PeerTreeview");
            Ticker.Tick ();
            BuildFileTreeView();
            Ticker.Tock ("FileTreeview");
            Ticker.Tick ();
            BuildLabelTreeView();
            Ticker.Tock ("Label treeview");
            Ticker.Tick ();
            BuildOptionsPage();
            Ticker.Tock ("Options page");
            Ticker.Tick ();
            BuildSpeedsPopup();
            Ticker.Tock ("Speeds popup");
            Ticker.Tock ("Built all stuff");

            GLib.Timeout.Add (1000, new GLib.TimeoutHandler (updateView));

            Ticker.Tick ();
            RestoreInterfaceSettings ();
            Ticker.Tock ("Restored Interface");

            if (SettingsManager.Preferences.UpnpEnabled)
                portController.Start();

            Ticker.Tick ();
            try{
                torrentController.LoadStoredTorrents ();
            }catch (Exception ex) {
                Console.WriteLine (ex);
                Environment.Exit(414);
            }
            Ticker.Tock ("Loaded torrents");

            Ticker.Tick ();
            logger.Info ("Restoring labels");
            LabelController.Restore ();
            // Restore previously labeled torrents
            foreach (Download download in torrentController.Torrents){
                foreach (TorrentLabel l in LabelController.Labels) {
                    if (l.TruePaths == null)
                        continue;

                    if (Array.IndexOf <string> (l.TruePaths, download.Manager.Torrent.TorrentPath) < 0)
                        continue;

                    l.AddTorrent (download);
                }
            }
            Ticker.Tock ("Restored labels");

            torrentController.Initialise ();
            folderWatcher = new TorrentFolderWatcher (new DirectoryInfo (SettingsManager.Preferences.ImportLocation));
            folderWatcher.TorrentFound += delegate(object o, TorrentWatcherEventArgs e) {
                GLib.Idle.Add(Event.Wrap ((GLib.IdleHandler) delegate {
                    TorrentFound (o, e);
                    return false;
                }));
            };

            torrentController.SelectionChanged += delegate {
                updateToolBar ();
            };

            torrentController.ShouldRemove += HandleShouldRemove;

            if (SettingsManager.Preferences.ImportEnabled) {
                logger.Info ("Starting import folder watcher");
                folderWatcher.Start ();
            }

            logger.Info ("Starting RSS manager");
            rssManagerController = new RssManagerController(SettingsManager.EngineSettings);
            rssManagerController.TorrentFound += delegate(object sender, TorrentRssWatcherEventArgs e) {
                string savePath = e.Filter == null ? SettingsManager.EngineSettings.SavePath : e.Filter.SavePath;
                try {
                    LoadTorrent(e.Item.Link, true, false, false, null, savePath, true);
                } catch {
                    logger.Error("RSS Manager: Unable to add - " + e.Item.Title);
                }
            };
            logger.Info ("Started RSS manager");
            rssManagerController.StartWatchers();
            AddGConfListeners ();
            updateToolBar ();
            ShowAll();
        }
Beispiel #10
0
        public TorrentTreeView() : base()
        {
            Torrents = new ListStore(typeof(Download), typeof(string), typeof(string),
                                     typeof(int), typeof(string), typeof(string),
                                     typeof(string), typeof(string), typeof(string),
                                     typeof(string), typeof(string), typeof(string), typeof(string));

            FilterModel             = new Gtk.TreeModelFilter(Torrents, null);
            FilterModel.VisibleFunc = delegate(TreeModel model, TreeIter iter) {
                return(Filter == null ? true : Filter((Download)model.GetValue(iter, 0)));
            };
            Model = FilterModel;
            this.torrentController = ServiceManager.Get <TorrentController> ();

            buildColumns();

            Reorderable        = true;
            HeadersVisible     = true;
            HeadersClickable   = true;
            Selection.Mode     = SelectionMode.Multiple;
            Selection.Changed += Event.Wrap(delegate(object o, EventArgs e) {
                TreeIter iter;
                TreePath [] selectedTorrents = Selection.GetSelectedRows();

                List <Download> downloads = new List <Download> ();
                foreach (TreePath path in Selection.GetSelectedRows())
                {
                    if (Torrents.GetIter(out iter, path))
                    {
                        downloads.Add((Download)Torrents.GetValue(iter, 0));
                    }
                }

                torrentController.Select(downloads);
            });

            sourceEntries = new TargetEntry [] {
                new TargetEntry(RowAtom.Name, TargetFlags.App, 0)
            };
            targetEntries = new TargetEntry [] {
                new TargetEntry(RowAtom.Name, TargetFlags.Widget, 0),
                new TargetEntry(FileAtom.Name, TargetFlags.OtherApp, 0)
            };
            EnableModelDragSource(Gdk.ModifierType.Button1Mask, sourceEntries, Gdk.DragAction.Copy);
            EnableModelDragDest(targetEntries, Gdk.DragAction.Copy);
            DragDataGet += OnTorrentDragDataGet;

            menu = new TorrentContextMenu();
            torrentController.Added += delegate(object sender, DownloadAddedEventArgs e) {
                AddDownload(e.Download);
            };
            torrentController.Removed += delegate(object sender, DownloadAddedEventArgs e) {
                RemoveDownload(e.Download);
            };

            LabelController lc = ServiceManager.Get <LabelController> ();

            lc.SelectionChanged += delegate {
                TorrentLabel label = lc.Selection;
                Filter = delegate(Download download) {
                    return(label.Torrents.Contains(download));
                };
            };

            // FIXME: This shouldn't be necessary
            torrentController.Torrents.ForEach(AddDownload);
        }
        public TorrentTreeView()
            : base()
        {
            Torrents = new ListStore (typeof (Download), typeof (string), typeof (string),
                                   typeof (int), typeof (string), typeof (string),
                                   typeof (string), typeof (string), typeof (string),
                                   typeof (string), typeof (string), typeof (string), typeof (string));

            FilterModel = new Gtk.TreeModelFilter (Torrents, null);
            FilterModel.VisibleFunc = delegate (TreeModel model, TreeIter iter) {
                return Filter == null ? true : Filter ((Download) model.GetValue (iter, 0));
            };
            Model = FilterModel;
            this.torrentController = ServiceManager.Get <TorrentController> ();

            buildColumns();

            Reorderable = true;
            HeadersVisible = true;
            HeadersClickable = true;
            Selection.Mode = SelectionMode.Multiple;
            Selection.Changed += Event.Wrap (delegate (object o, EventArgs e) {
                TreeIter iter;
                TreePath [] selectedTorrents = Selection.GetSelectedRows ();

                List <Download> downloads = new List<Download> ();
                foreach (TreePath path in Selection.GetSelectedRows ()) {
                    if (Torrents.GetIter (out iter, path)) {
                        downloads.Add ((Download) Torrents.GetValue (iter, 0));
                    }
                }

                torrentController.Select (downloads);
            });

            sourceEntries = new TargetEntry [] {
                new TargetEntry(RowAtom.Name, TargetFlags.App, 0)
            };
            targetEntries = new TargetEntry [] {
                new TargetEntry(RowAtom.Name, TargetFlags.Widget, 0),
                new TargetEntry(FileAtom.Name, TargetFlags.OtherApp, 0)
            };
            EnableModelDragSource(Gdk.ModifierType.Button1Mask, sourceEntries, Gdk.DragAction.Copy);
            EnableModelDragDest(targetEntries, Gdk.DragAction.Copy);
            DragDataGet += OnTorrentDragDataGet;

            menu = new TorrentContextMenu ();
            torrentController.Added += delegate(object sender, DownloadAddedEventArgs e) {
                AddDownload (e.Download);
            };
            torrentController.Removed += delegate(object sender, DownloadAddedEventArgs e) {
                RemoveDownload (e.Download);
            };

            LabelController lc = ServiceManager.Get <LabelController> ();
            lc.SelectionChanged += delegate {
                TorrentLabel label = lc.Selection;
                Filter = delegate (Download download) {
                    return label.Torrents.Contains (download);
                };
            };

            // FIXME: This shouldn't be necessary
            torrentController.Torrents.ForEach (AddDownload);
        }