Esempio n. 1
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            TransmissionAPI api = TransmissionPlugin.getTransmission();

            // Operation is common for all files.
            TransmissionAPI.FileOperation operation = new TransmissionAPI.FileOperation(true, null);

            // Group selected items by owner torrent.
            var files_by_torrent = items
                                   .Cast <ITorrentEntry>()
                                   .GroupBy(
                item => item.Torrent,
                (torrent, entries) => new {
                Torrent = torrent,
                Files   = entries.SelectMany(entry => entry.GetFiles())
            }
                );

            // Perform action for each torrent separately.
            foreach (var group in files_by_torrent)
            {
                var operations = group.Files.ToDictionary(f => f.Index, f => operation);
                api.SetTorrent(group.Torrent.HashString, null, null, null, null, null, operations);
            }

            yield break;
        }
Esempio n. 2
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            TransmissionAPI.FilePriority priority = (modItems.First() as PriorityItem).Value;

            TransmissionAPI.FileOperation operation = new TransmissionAPI.FileOperation(null, priority);

            // Group torrent entries by torrent.
            var files_by_torrent = items
                                   .Cast <ITorrentEntry>()
                                   .GroupBy(
                item => item.Torrent,
                (torrent, entries) => new {
                Torrent = torrent,
                Files   = entries.SelectMany(entry => entry.GetFiles())
            }
                );

            TransmissionAPI api = TransmissionPlugin.getTransmission();

            // Expand entries for each torrent into set of torrent file entries.
            // Perform action for each torrent separately.
            foreach (var group in files_by_torrent)
            {
                var operations = group.Files.ToDictionary(f => f.Index, f => operation);
                api.SetTorrent(group.Torrent.HashString, null, null, null, null, null, operations);
            }

            yield break;
        }
Esempio n. 3
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            TransmissionAPI api = TransmissionPlugin.getTransmission();

            var hashes = items.Cast <TorrentItem>().Select(t => t.HashString);

            api.VerifyTorrents(hashes);

            return(null);
        }
Esempio n. 4
0
        public override void UpdateItems()
        {
            Log <TorrentItemSource> .Debug("Updating torrents list");

            // Clear current torrents list.
            _torrents.Clear();

            TransmissionAPI api = TransmissionPlugin.getTransmission();

            foreach (TransmissionAPI.TorrentInfo t in api.GetAllTorrents())
            {
                Log <TorrentItemSource> .Debug("Torrent: {0}", t.Name);

                TorrentItem torrent = new TorrentItem(t);

                // Transmission returns files as flat list with full names, this map
                // is used to organize files into hierarchy.
                // It maps directory path to directory item.
                Dictionary <string, TorrentDirectoryItem> dirs = new Dictionary <string, TorrentDirectoryItem>();
                dirs.Add("", torrent.Root);

                int index = 0;                 // File index within list.
                foreach (TransmissionAPI.TorrentFileInfo f in t.Files)
                {
                    // Split path and name.
                    int sep_pos = f.Name.LastIndexOf('/');

                    string name = f.Name.Substring(sep_pos + 1);
                    string path = f.Name.Substring(0, sep_pos == -1 ? 0 : sep_pos);
                    Log <TorrentItemSource> .Debug("File {0} in dir {1}", name, path);

                    TorrentDirectoryItem dir = FindOrCreateDirectory(path, dirs);

                    dir.Files.Add(new TorrentFileItem(torrent, index, dir, name, f));

                    ++index;
                }

                _torrents.Add(torrent);
            }
        }
Esempio n. 5
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            int?speed = null;

            // Get speed item, it can be either ITextItem or PredefinedSpeed.
            Item modItem = modItems.First();

            if (modItem is PredefinedSpeed)
            {
                speed = ((PredefinedSpeed)modItem).Value;
            }
            else
            {
                string speed_str = ((ITextItem)modItem).Text;

                try {
                    // Try to parse entered speed value.
                    speed = Utils.ParseSpeed(speed_str);
                } catch (ArgumentException) {
                    Log <TransmissionPlugin> .Debug("Invalid speed string: {0}", speed_str);

                    // Show notification about invalid speed value with some hints on
                    // accepted formats.
                    string message = AddinManager.CurrentLocalizer.GetString(
                        "Can't recognize \"{0}\" as speed\nUse values like: 100k, 50 kb, 20m, 10 mib"
                        );
                    Services.Notifications.Notify("Transmission", string.Format(message, speed_str), "transmission");
                }
            }

            // If speed is recognized successfully, set speed limit and update item.
            if (speed.HasValue)
            {
                TransmissionAPI           api      = TransmissionPlugin.getTransmission();
                IEnumerable <TorrentItem> torrents = items.Cast <TorrentItem>();
                SetSpeedLimit(api, torrents, speed.Value);
            }

            yield break;
        }
Esempio n. 6
0
 protected virtual void OnPortEntryChanged(object sender, System.EventArgs e)
 {
     Port = int.Parse(port_entry.Text);
     TransmissionPlugin.ResetConnection();
 }
Esempio n. 7
0
 protected virtual void OnPasswordEntryChanged(object sender, System.EventArgs e)
 {
     Password = password_entry.Text;
     TransmissionPlugin.ResetConnection();
 }
Esempio n. 8
0
 protected virtual void OnUserNameEntryChanged(object sender, System.EventArgs e)
 {
     UserName = user_name_entry.Text;
     TransmissionPlugin.ResetConnection();
 }
Esempio n. 9
0
 protected virtual void OnAddressEntryChanged(object sender, System.EventArgs e)
 {
     Address = address_entry.Text;
     TransmissionPlugin.ResetConnection();
 }