예제 #1
0
        /// <summary>
        /// Returns a 16 by 16 icon that indicates a particular state of downloading the enclosure.
        /// </summary>
        /// <param name="state">Enclosure download state.</param>
        /// <returns>The icon (the same instance for the same parameters).</returns>
        public static Icon GetEnclosureStateIcon(EnclosureDownloadState state)
        {
            if (!Core.UserInterfaceAP.IsOwnerThread)
            {
                throw new InvalidOperationException("This method must be accessed only from the User Interface Async Processor thread.");
            }

            // Load the icons on the first call
            if (_arEnclosureStateIcons == null)
            {
                _arEnclosureStateIcons = new Icon[5];

                String[] sNames = new[] { "NotDownloaded", "Planned", "Completed", "Failed", "InProgress" };
                for (int a = 0; a < sNames.Length; a++)
                {
                    _arEnclosureStateIcons[a] = RSSPlugin.LoadIconFromAssembly(string.Format("download{0}.ico", sNames[a]));
                }
            }

            // Range check
            if ((state < EnclosureDownloadState.MinValue) || (state >= EnclosureDownloadState.MaxValue))
            {
                throw new ArgumentException("The enclosure download state is out of range.");
            }

            // Hand out the icon
            return(_arEnclosureStateIcons[(int)state]);
        }
예제 #2
0
        public Icon[] GetOverlayIcons(IResource resource)
        {
            string updateStatus = resource.GetStringProp(Props.UpdateStatus);

            if (updateStatus == "(updating)")
            {
                if (_updating == null)
                {
                    _updating    = new Icon[1];
                    _updating[0] = RSSPlugin.LoadIconFromAssembly("updating.ico");
                }
                return(_updating);
            }
            if (updateStatus == "(error)")
            {
                if (_error == null)
                {
                    _error    = new Icon[1];
                    _error[0] = RSSPlugin.LoadIconFromAssembly("error.ico");
                }
                return(_error);
            }
            if (resource.HasProp(Props.IsPaused))
            {
                if (_paused == null)
                {
                    _paused    = new Icon[1];
                    _paused[0] = RSSPlugin.LoadIconFromAssembly("RSSFeedPaused.ico");
                }
                return(_paused);
            }
            return(null);
        }
예제 #3
0
        public Icon GetResourceIcon(IResource resource)
        {
            // Try to get the feed's favicon
            Icon favicon = TryGetResourceIcon(resource);

            if (favicon != null)
            {
                return(favicon);
            }

            // No favicon available, return resource-type's default icon (lazy loading)
            if (_default == null)
            {
                _default = RSSPlugin.LoadIconFromAssembly("RSSFeed.ico");
            }

            return(_default);
        }
예제 #4
0
        public void GetItemHtml(IResource item, TextWriter writer)
        {
            TextWriterDecor decor = new TextWriterDecor(writer);

            ////////////////////////
            // Prepare the strings

            /*
             * // Date — date/time of this item
             * string sDate;
             * DateTime date = item.GetDateProp( Core.Props.Date );
             * if( date.Date == DateTime.Today )
             * sDate = "Today " + date.ToShortTimeString();
             * else
             * sDate = date.ToShortDateString() + ' ' + date.ToShortTimeString();
             *
             * // Origin — name of the feed author, etc
             * string sOrigin = "";
             * if( item.HasProp( Core.ContactManager.Props.LinkFrom ) )
             * sOrigin = HttpUtility.HtmlEncode( item.GetPropText( Core.ContactManager.Props.LinkFrom ) );
             *
             * //////////
             * // Title
             * writer.WriteLine( "<div class=\"title\">" );
             * GenericNewspaperProvider.RenderIcon( item, writer ); // Icon
             * RssBodyConstructor.AppendLink( item, decor, true ); // Title text & link
             * writer.WriteLine( "<em class=\"Origin\">{0}{2}{1}</em>", sOrigin, sDate, ((sOrigin.Length > 0) && (sDate.Length > 0) ? " — " : "") ); // Origin (feed name) & Date
             * writer.WriteLine( "</div>" ); // class=title
             *
             * GenericNewspaperProvider.RenderFlag( item, writer ); // Flag (optional)
             * GenericNewspaperProvider.RenderAnnotation( item, writer ); // Annotation (optional)
             *
             * writer.WriteLine( "<br class=\"clear\" />" );
             */
            // TODO: remove

            IResource feed = item.GetLinkProp(-Props.RSSItem);

            GenericNewspaperProvider.RenderCaption(item, writer);

            //////////////
            // Item Body

            writer.WriteLine("<div>");
            if (feed != null && feed.HasProp(Props.URL))
            {
                writer.WriteLine(HtmlTools.FixRelativeLinks(item.GetPropText(Core.Props.LongBody), feed.GetStringProp("URL")));
            }
            else
            {
                writer.WriteLine(item.GetPropText(Core.Props.LongBody));
            }
            writer.WriteLine("</div>");

            // Enclosure info
            if (item.HasProp(Props.EnclosureURL))
            {
                writer.Write("<p class=\"Origin\"><span title=\"Enclosure is an attachment to the RSS feed item.\">Enclosure</span>");

                // Specify the enclosure size, if available
                if (item.HasProp(Props.EnclosureSize))
                {
                    writer.Write(" ({0})", Utils.SizeToString(item.GetIntProp(Props.EnclosureSize)));
                }

                writer.Write(": ");

                // Add a link to the locally-saved enclosure file
                string sDownloadComment = null;                 // Will contain an optional download comment
                if (item.HasProp(Props.EnclosureDownloadingState))
                {
                    // Choose the tooltip text and whether the icon will be clickable, depending on the state
                    string sText = null;
                    bool   bLink = false;
                    EnclosureDownloadState nEnclosureDownloadState = (EnclosureDownloadState)item.GetIntProp(Props.EnclosureDownloadingState);
                    switch (nEnclosureDownloadState)
                    {
                    case EnclosureDownloadState.Completed:
                        sText = "The enclosure has been downloaded to your computer.\nClick to open the local file.";
                        bLink = true;
                        break;

                    case EnclosureDownloadState.Failed:
                        sText = "Failed to download the enclosure.\nUse the Web link to download manually.";
                        break;

                    case EnclosureDownloadState.InProgress:
                        sText = "Downloading the enclosure, please wait…\nClick to open the partially-downloaded file.";
                        // Write percentage to the comment
                        if (item.HasProp(Props.EnclosureDownloadedSize))
                        {
                            if (item.HasProp(Props.EnclosureSize))                                // The total size is available, as needed for the percentage
                            {
                                sDownloadComment = String.Format("({0}%)", item.GetIntProp(Props.EnclosureDownloadedSize) * 100 / item.GetIntProp(Props.EnclosureSize));
                            }
                            else                             // The total size is not available, percentage not available, show the size downloaded
                            {
                                sDownloadComment = String.Format("({0} downloaded so far)", Utils.SizeToString(item.GetIntProp(Props.EnclosureDownloadedSize)));
                            }
                        }
                        bLink = true;
                        break;

                    case EnclosureDownloadState.NotDownloaded:
                        sText = "The enclosure has not been downloaded.\nUse the Web link to download manually.";
                        break;

                    case EnclosureDownloadState.Planned:
                        sText            = "The enclosure has been schedulled for download.\nUse the Web link to download manually.";
                        sDownloadComment = "(0%)";
                        break;

                    default:
                        throw new Exception("Unexpected enclosure download state.");
                    }

                    // Ensure that there's the path to the local file specified, if we're going to provide a link to it
                    if ((bLink) && (!item.HasProp(Props.EnclosureTempFile)))
                    {
                        Trace.WriteLine("Warning: path to the downloaded or in-progress enclosure is missing, though the downloading state implies on it should be present.");
                        bLink = false;
                    }

                    // Open the link (if available)
                    if (bLink)
                    {
                        writer.Write("<a href=\"{0}\">", "file://" + HttpUtility.HtmlEncode(item.GetStringProp(Props.EnclosureTempFile)));
                    }

                    // Render the icon
                    Icon icon = EnclosureDownloadManager.GetEnclosureStateIcon(nEnclosureDownloadState);
                    writer.Write("<img src=\"{0}\" align=\"top\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" title=\"{3}\" />", FavIconManager.GetIconFile(icon, "EnclosureDownload", null, true), icon.Width, icon.Height, sText, sText);

                    // Close the link
                    if (bLink)
                    {
                        writer.Write("</a>");
                    }

                    writer.Write(" ");
                }

                // Add a link to the Web location of the enclosure
                writer.Write("<a href=\"{0}\">", HttpUtility.HtmlEncode(item.GetStringProp(Props.EnclosureURL)));
                if (_iconEnclosureWeb == null)
                {
                    _iconEnclosureWeb = RSSPlugin.LoadIconFromAssembly("BlogExtensionComposer.Submit.ico");
                }
                writer.Write("<img src=\"{0}\" align=\"top\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" title=\"{3}\" /> ", FavIconManager.GetIconFile(_iconEnclosureWeb, "EnclosureWeb", null, true), _iconEnclosureWeb.Width, _iconEnclosureWeb.Height, "Download enclosure from the Web.");
                writer.Write("</a>");

                // Add the optional download comment
                if (sDownloadComment != null)
                {
                    writer.Write(" ");
                }
                writer.Write(sDownloadComment);

                // Close the paragraph
                writer.WriteLine("</p>");
            }

            // Link to the Source
            RssBodyConstructor.AppendSourceTag(item, decor);

            // Link to the comments
            if (item.HasProp(Props.CommentURL))
            {
                decor.AppendText("<p class=\"Origin\">");
                RssBodyConstructor.AppendCommentsTag(item, decor);
                writer.WriteLine("</p>");
            }
        }
예제 #5
0
        public void RegisterViewsFirstRun()
        {
            IResource res;

            string[]        applType = new string[] { "RSSItem" };
            IFilterRegistry fMgr     = Core.FilterRegistry;

            //-----------------------------------------------------------------
            //  All conditions, templates and actions must have their deep names
            //-----------------------------------------------------------------
            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.AuthorWrotePostName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.AuthorWrotePostDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.AuthorHasFeedName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.AuthorHasFeedDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.PostHasEnclosuredName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.PostHasEnclosuredDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.PostHasCommentName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.PostHasCommentDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.DownloadFailedName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.DownloadFailedDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.DownloadCompletedName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.DownloadCompletedDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.DownloadNotName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.DownloadNotDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionResName, "Name", RSSViewsConstructor.DownloadPlannedName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.DownloadPlannedDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionTemplateResName, "Name", RSSViewsConstructor.PostInFeedName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.PostInFeedDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionTemplateResName, "Name", RSSViewsConstructor.PostInCategoryName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.PostInCategoryDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionTemplateResName, "Name", RSSViewsConstructor.EnclosureSizeName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.EnclosureSizeDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ConditionTemplateResName, "Name", RSSViewsConstructor.EnclosureTypeName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.EnclosureTypeDeep);
            }

            res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.RuleActionResName, "Name", RSSViewsConstructor.DownloadEnclosureName);
            if (res != null)
            {
                res.SetProp("DeepName", RSSViewsConstructor.DownloadEnclosureDeep);
            }

            //  Tray Icon Rules and Notifications
            Core.TrayIconManager.RegisterTrayIconRule("Unread RSS/ATOM Posts", applType, new IResource[] { fMgr.Std.ResourceIsUnread },
                                                      null, RSSPlugin.LoadIconFromAssembly("RSSItemUnread.ico"));
        }