public bool CollectUnreadItems(UnreadItemCollection unreadFeeds, UnreadItemCollection unreadTags, List<string> identifierFilterList) { bool result = true; //int unreadCount; XmlDocument xdoc; result = LoggedIn; if (result) { xdoc = this.GetAllUnreadCountsXMLDocument(); // Collect feed information if (unreadFeeds != null) { unreadFeeds.Clear(); CollectUnreadItemsBySelectedNodes(xdoc, "//object/string[contains(.,'feed/http')]", unreadFeeds, LocateFeedIdentifier, null); } // Collect tag information if (unreadTags != null) { unreadTags.Clear(); CollectUnreadItemsBySelectedNodes(xdoc, "//object/string[contains(.,'/label/') and contains(.,'user/')]", unreadTags, LocateTagIdentifier, identifierFilterList); } } return result; }
public bool CollectUnreadFeeds(UnreadItemCollection unreadFeeds) { System.Diagnostics.Debug.Assert(unreadFeeds != null, "unreadFeeds must be assigned."); return CollectUnreadItems(unreadFeeds, null, null); }
private void CollectUnreadItemsBySelectedNodes(XmlDocument xdoc, string nodeSelection, UnreadItemCollection unreadItems, LocateUnreadItemIdentifierDelegate locateIdentifierDelegate, List<string> identifierFilterList) { int unreadCount; UnreadItem unreadItem; string identifier; bool addToList; foreach (XmlNode node in xdoc.SelectNodes(nodeSelection)) { unreadCount = Convert.ToInt32(node.ParentNode.SelectSingleNode("number").InnerText); identifier = locateIdentifierDelegate(node.InnerText); addToList = (unreadCount > 0) && ((identifierFilterList == null) || identifierFilterList.Contains(identifier)); if (addToList) { unreadItem = new UnreadItem(); unreadItem.Identifier = identifier; unreadItem.ArticleCount = unreadCount; unreadItems.Add(unreadItem); } } }
public bool CollectUnreadTags(UnreadItemCollection unreadTags, List<string> tagFilterList) { System.Diagnostics.Debug.Assert(unreadTags != null, "unreadTags must be assigned."); return CollectUnreadItems(null, unreadTags, tagFilterList); }
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; }
private void CheckForUpdates() { bool collectionResult; UnreadItemCollection unreadItems = new UnreadItemCollection(); try { // if there are no errors, this will be restarted. //_checkForUpdatesTimer.Stop();//but what if not? it should never stop. //verify the user has entered credentials if (this.VerifyLoginEntered()) { //call the Google API GoogleReader reader = new GoogleReader(); reader.Login(_username, _password); if (HasFilterTags()) { collectionResult = reader.CollectUnreadTags(unreadItems, _tagFilter); } else { collectionResult = reader.CollectUnreadFeeds(unreadItems); } if (collectionResult) { this.DisplayUnreadItems(unreadItems); _checkForUpdatesTimer.Start(); } } } catch{} }