private void DisplayUnreadItems(UnreadItemCollection unreadItems)
        {
            int newUnreadCount;
            int oldUnreadCount = 0;
            int newSinceLastUpdateCount = 0;
            string displayInformation = "";
            string tooltipInformation = "";
            bool showNotification;

            if (unreadItems.Count > 0)
            {
                newUnreadCount = unreadItems.TotalUnreadItemArticles();

                if (_currentUnreadItems != null)
                {
                    oldUnreadCount = _currentUnreadItems.TotalUnreadItemArticles();
                    newSinceLastUpdateCount = CountNewSinceLastUpdate(unreadItems);
                }

                // if the there were previously no unread items, or if the overall unread items
                // has increased, or if there are new ones since the last check, then notify the user.
                showNotification = (_currentUnreadItems == null) ||
                    (newUnreadCount > oldUnreadCount) || (newSinceLastUpdateCount > 0);

                tooltipInformation = String.Format("{0} unread items", newUnreadCount);
                displayInformation = tooltipInformation;

                if (newSinceLastUpdateCount > 0)
                {
                    displayInformation = String.Format("{0} unread items ({1} new)", newUnreadCount, newSinceLastUpdateCount);
                }

                // if the option is enabled, change the tooltip text
                if (_showCountTooltip)
                {
                    if (tooltipInformation.Length < 64)
                    {
                        _notifyIcon.Text = tooltipInformation;
                    }
                }

                // if we need to notify user of changes and the animation is turned on, show the animation code
                if (showNotification)
                {
                    // play notification sound if configured
                    UserPreferences prefs = PreferencesHelper.RetrievePreferences();

                    if (prefs.HasNotificationAudioFilePath)
                    {
                        System.Media.SoundPlayer player = new System.Media.SoundPlayer();

                        player.SoundLocation = prefs.NotificationAudioFilePath;
                        try
                        {
                            player.Play();
                        }
                        catch { }
                    }

                    if (_animatePopup)
                    {
                        if (SnarlConnector.GetSnarlWindow() != IntPtr.Zero)
                        {
                            Snarl.SnarlConnector.ShowMessageEx("New items", "New items", displayInformation, 15, iconPath, snarlMsgWindowHandle, Snarl.WindowsMessage.WM_USER + 17, "");
                        }
                        else
                        {
                            this.ShowTrayNotification(displayInformation);
                        }
                    }
                }

                _notifyIcon.Icon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("GoogleReaderNotifier.WinUI.Images.unread"+_unreadIcon+".ico"));
                _currentUnreadItems = unreadItems;
            }
            else
            {
                _currentUnreadItems = null;
                ResetTrayIcon();
                _notifyIcon.Text = "0 unread items";
            }
        }
        private int CountNewSinceLastUpdate(UnreadItemCollection newUnreadItems)
        {
            int result = 0;
            UnreadItem oldUnreadItem;

            if (_currentUnreadItems == null)
            {
                result = newUnreadItems.TotalUnreadItemArticles();
            }
            else
            {
                foreach (UnreadItem newItem in newUnreadItems)
                {
                    oldUnreadItem = _currentUnreadItems.UnreadItemByIdentifier(newItem.Identifier);

                    if (oldUnreadItem == null)
                    {
                        result += newItem.ArticleCount;
                    }
                    else
                    {
                        if (newItem.ArticleCount > oldUnreadItem.ArticleCount)
                        {
                            result += newItem.ArticleCount - oldUnreadItem.ArticleCount;
                        }
                    }
                }
            }

            return result;
        }