///RSSChannelManager channelManager = RSSChannelManager.Instance();

        //GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", channelManager.Channels.Count));
        //add utorrent inbuit rss feeds

        //if (TorrentEngine.Instance().TorrentSession.GetType() == typeof(UTorrentClient))
        //{
        //    GUIListItem item = new GUIListItem();
        //    item.Label = "UTorrent Inbuit RSS Feeds";
        //    item.AlbumInfoTag = RSSParser.GetUtorrentFeeds(UTorrentClient.baseresponse);
        //    rssList.Add(item);
        //}

        public List <GUIListItem> ShowRSS()
        {
            List <GUIListItem> rsslist = new List <GUIListItem>();

            rsslist.Clear();
            RSSChannelManager.Instance().UpdateChannels(true);
            //channelManager.UpdateChannels(true);
            foreach (IRSSChannel channel in RSSChannelManager.Instance().Channels)
            {
                GUIListItem listItem = new GUIListItem();
                listItem.Label        = channel.Title + " " + channel.Description;
                listItem.Label2       = channel.Updated.ToShortDateString() + " " + channel.Updated.ToShortTimeString();
                listItem.AlbumInfoTag = channel;
                rsslist.Add(listItem);
            }
            return(rsslist);
        }
        public void ContextMenu(object info)
        {
            WatchItem     watch = info as WatchItem;
            GUIDialogMenu dlg   = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }


            dlg.Reset();
            dlg.SetHeading("Torrent watchlist");
            dlg.Add("Add Series");
            dlg.Add("Search Series");
            dlg.Add("Add Movie");
            dlg.Add("Add custom");
            dlg.Add("Manual Search");
            dlg.Add("Remove selected");
            dlg.Add("Clear list");
            dlg.Add("Force RSS update");
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlg.SelectedLabelText)
            {
            case "Add Series":
            {
                AddSeries();
                MyTorrents.Instance().ShowTorrentWatch();
                break;
            }

            case "Search Series":
            {
                SearchSeries();
            }
            break;

            case "Add Movie":
                break;

            case "Manual Search":
                MyTorrents.Instance()._torrentWatchlist.SearchTorrent();
                break;

            case "Add custom":
            {
                VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
                keyboard.Reset();
                keyboard.Text = "";
                keyboard.DoModal(GUIWindowManager.ActiveWindow);

                if (!keyboard.IsConfirmed)
                {
                    return;
                }

                watch            = new WatchItem();
                watch.SearchTerm = keyboard.Text;

                TorrentLabel label = DialogAskLabel.Ask();
                if (label != null)
                {
                    watch.Label = label.Name;
                    MyTorrents.Instance()._torrentWatchlist.AddWatch(watch);
                    Log.Instance().Print(String.Format("Watch [{0}] added.", watch.SearchTerm));
                }
                break;
            }

            case "Clear list":
            {
                MyTorrents.Instance()._torrentWatchlist.Clear();
                break;
            }

            case "Remove selected":
            {
                MyTorrents.Instance()._torrentWatchlist.RemoveWatch(watch);
                // torrentList.RemoveItem(torrentList.SelectedListItemIndex);
                break;
            }

            case "Force RSS update":
            {
                RSSChannelManager.Instance().UpdateChannels(true);
                break;
            }
            }

            MyTorrents.Instance().ShowTorrentWatch();
        }
        public bool LoadRssChannels(ConfigData _config)
        {
            XmlDocument       xmlDoc         = _config.MyTorrentsConfiguration;
            RSSChannelManager channelManager = RSSChannelManager.Instance();
            XmlNodeList       nodes          = xmlDoc.SelectSingleNode("config/feed").ChildNodes;

            foreach (XmlNode node in nodes)
            {
                IRSSChannel rssChannel = null;
                string      type       = "";
                if (node.Name == "rss")
                {
                    type = "rss";
                }
                if (node.Name == "atom")
                {
                    type = "atom";
                }
                XmlNodeList nUrls = node.SelectNodes("url");
                if (nUrls.Count >= 2)
                {
                    //combined!
                    XmlNode nTitle = node.SelectSingleNode("title");
                    XmlNode nDesc  = node.SelectSingleNode("description");

                    if (nTitle == null || nDesc == null)
                    {
                        continue;
                    }
                    RSSCombined combined = new RSSCombined(nTitle.InnerText, nDesc.InnerText);

                    foreach (XmlNode nUrl in node.SelectNodes("url"))
                    {
                        RSSChannel channel = new RSSChannel(nUrl.InnerText);

                        combined.Channels.Add(channel);
                    }
                    rssChannel = combined;
                }
                else
                {
                    if (node.SelectSingleNode("transform") != null)
                    {
                        XmlNode nurl         = node.SelectSingleNode("url");
                        XmlNode trans        = node.SelectSingleNode("transform/origin");
                        XmlNode basedownload = node.SelectSingleNode("transform/basedownload");
                        rssChannel = new RSSChannel(nurl.InnerText, new Regex(trans.InnerText, RegexOptions.IgnoreCase), basedownload.InnerText);
                    }
                    else
                    {
                        XmlNode nUrl = node.SelectSingleNode("url");
                        rssChannel = new RSSChannel(nUrl.InnerText);
                    }
                }
                XmlNode expireTime = node.SelectSingleNode("expires");

                if (expireTime == null)
                {
                    //5minutes
                    rssChannel.ExpireTime = new TimeSpan(0, 5, 0);
                }
                else
                {
                    rssChannel.ExpireTime = new TimeSpan(0, 0, Convert.ToInt32(expireTime.InnerText));
                }
                rssChannel.Type = type;
                channelManager.Channels.Add(rssChannel);
            }

            Log.Instance().Print("Started RssChanel");


            return(true);
        }
        public IRSSChannel RSSContextMenu(IRSSChannel channel)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return(null);
            }

            dlg.Reset();
            dlg.SetHeading("RSS Feeds");
            dlg.Add("Search");
            dlg.Add("Update selected");
            dlg.Add("Update all");
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlg.SelectedLabelText)
            {
            case "Update selected":
            {
                if (channel == null)
                {
                    return(null);
                }
                if (channel != null)
                {
                    channel.Update();
                }
                return(null);
            }

            case "Update all":
            {
                RSSChannelManager.Instance().UpdateChannels(true);
                return(null);
            }

            case "Search":
            {
                VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
                keyboard.Reset();
                keyboard.Text = "";
                keyboard.DoModal(GUIWindowManager.ActiveWindow);

                if (!keyboard.IsConfirmed)
                {
                    return(null);
                }

                Regex re = new Regex(keyboard.Text, RegexOptions.IgnoreCase);

                RSSChannel search = new RSSChannel("MediaPortal");
                if (channel != null && channel.Url != "MediaPortal")
                {
                    foreach (RSSItem item in channel.Items)
                    {
                        if (re.IsMatch(item.Title))
                        {
                            search.Items.Add(item);
                        }
                    }
                }
                //this.ShowSelectedRSS() = search;
                //UpdateListItems();
                return(search);
            }
            }
            return(null);
        }