/// <summary> /// Adds a news feed to the sql database. /// </summary> public void AddFeed(Feed feed) { string sql = "INSERT INTO feed VALUES (NULL, '" + parseSql (feed.Name) + "','" + parseSql (feed.Url) + "','" + parseSql (feed.ETag) + "','" + parseSql (feed.LastModified) + "','" + feed.AutoRefresh.ToString () + "')"; executeSql (sql); string feed_id = getFeedID (feed); if (feed_id == "-1") return; foreach (Item item in feed.Items) addItem (item, feed_id); }
// create the context menu public FeedContextMenu(Feed feed, MainPage page) : base() { this.feed = feed; this.page = page; ImageMenuItem refresh_feed = new ImageMenuItem (Stock.Refresh, null); ImageMenuItem remove_feed = new ImageMenuItem (Stock.Remove, null); CheckMenuItem autorefresh = new CheckMenuItem ("Auto-Refresh"); this.Add (refresh_feed); this.Add (autorefresh); this.Add (new SeparatorMenuItem ()); this.Add (remove_feed); autorefresh.Active = feed.AutoRefresh; refresh_feed.Activated += refresh_activated; remove_feed.Activated += remove_activated; autorefresh.Toggled += autorefresh_toggled; }
/// <summary> /// Loads a single item into the html widget. /// </summary> public void LoadItem(Item item, Feed feed) { if (item == null || feed == null) return; page_number = 0; page_count = 0; this.feed = null; // render item into html string output = template.Replace ("@fuse_feed_name@", feed.Name); output = output.Replace ("@fuse_link@", item.Url); output = output.Replace ("@fuse_header@", item.Title); output = output.Replace ("@fuse_description@", item.Description); item.Read = true; parent.DataManager.UpdateItem (item); html.RenderData (output, feed.Url, "text/html"); feed.UpdateStatus (); }
/// <summary> /// Load the feed items into the html widget. /// </summary> public void LoadFeed(Feed feed) { this.feed = feed; page_number = 0; if (feed.Items.Count > 0) { double item_count = (double) feed.Items.Count; double show_count = (double) show_total+1; page_count = (int) Math.Ceiling (item_count / show_count); } else page_count = 0; showPage (); }
// loads the feed into the popup private void loadFeed(Feed feed) { page_number = 0; unread_items.Clear (); //find all the unread items foreach (Item item in feed.Items) if (item.IsNew) unread_items.Add (item); //create the links to be used in the popup links = new LinkButton[unread_items.Count]; for (int i=0; i<unread_items.Count; i++) { Item item = unread_items[i]; links[i] = new LinkButton (item.Url, item.Title); links[i].Xalign = 0; links[i].EnterNotifyEvent += button_enter; links[i].LeaveNotifyEvent += button_leave; //the link has been clicked links[i].Clicked += delegate (object o, EventArgs args) { parent.News.NewsViewer.LoadItem (item, feed); feed.UpdateStatus (); unread.Markup = feed.UnreadStatus; parent.News.NewsTree.QueueDraw (); }; } //get the amount of pages if (unread_items.Count > 0) { double item_count = (double) unread_items.Count; double show_count = (double) show_total+1; page_count = (int) Math.Ceiling (item_count / show_count); } else page_count = 0; //update the feed details title.Markup = Utils.ParseMarkup (feed.Name); unread.Markup = feed.UnreadStatus; refreshFeed (); //create the items generateItems (); }
// adds the new feed items void addNewItems(Feed feed, RssFeed rss_feed) { // only add in new items. backwards for (int i=rss_feed.Channel.Items.Count-1; i>=0; i--) { RssItem rss_item = rss_feed.Channel.Items [i]; bool exists = false; foreach (Item item in feed.Items) if (item.Title == rss_item.Title && item.Url == rss_item.Link && item.GUID == rss_item.Guid && item.PubDate == rss_item.PubDate) exists = true; // the list doesnt have the news item if (!exists) { Item new_item = new Item (rss_item); new_item.IsNew = true; // add in the new item Application.Invoke (delegate { feed.Items.Add (new_item); parent.DataManager.AddItem (feed, new_item); }); } } // update the feed Application.Invoke (delegate { feed.UpdateStatus (); parent.DataManager.UpdateFeed (feed); }); }
/// <summary> /// Refreshes the specified news feed. /// </summary> public void Refresh(Feed feed) { feed.Updating = true; Application.Invoke (delegate{ news_tree.QueueDraw (); }); //clear new item count foreach (Item item in feed.Items) item.IsNew = false; //update feed try { RssFeed rss_feed = new RssFeed (feed.Url, feed.ETag, feed.LastModified); if (rss_feed.Channel != null) addNewItems (feed, rss_feed); } catch (Exception e) { parent.Fuse.ThrowWarning ("News.Refresh:: Could not update the feed - " + feed.Url, e.ToString ()); } feed.Updating = false; //update view Application.Invoke (delegate{ news_tree.QueueDraw (); TreeIter iter; if (news_tree.Selection.GetSelected (out iter)) { Feed node = (Feed) news_store.GetValue (iter, 0); if (node.Url == feed.Url) news_viewer.Refresh (); } }); }
/// <summary> /// Adds a feed into the news store. /// </summary> public void AddFeed(RssFeed rss_feed) { Feed feed = new Feed (rss_feed); if (news_store.IterNChildren () > 0) news_store.AppendValues (new Feed ("ROW_SEP", "", "", "", false)); news_store.AppendValues (feed); parent.DataManager.AddFeed (feed); }
/// <summary> /// Deletes the specified news feed and its items from the database. /// </summary> public void DeleteFeed(Feed feed) { string feed_id = getFeedID (feed); string sql = "DELETE FROM feed WHERE url='" + feed.Url + "'"; executeSql (sql); sql = "DELETE FROM item WHERE feed_id='" + feed_id + "'"; executeSql (sql); }
/// <summary> /// Adds a news item into the sql database. /// </summary> public void AddItem(Feed feed, Item item) { string feed_id = getFeedID (feed); addItem (item, feed_id); }
// load the feed's items void loadItems(Feed feed) { string feed_id = getFeedID (feed); string sql = "SELECT title, description, url, guid, read, pub_date FROM item WHERE feed_id='" + feed_id + "'"; dbcon.Open (); IDbCommand dbcmd = dbcon.CreateCommand (); dbcmd.CommandText = sql; IDataReader reader = dbcmd.ExecuteReader (); while (reader.Read ()) { string title = reader.GetString (0); string description = reader.GetString (1); string url = reader.GetString (2); string guid = reader.GetString (3); bool read = reader.GetBoolean (4); string pub_date = reader.GetString (5); feed.Items.Add (new Item (title, description, url, guid, read, pub_date)); } reader.Close (); reader = null; dbcmd.Dispose (); dbcmd = null; dbcon.Close (); feed.UpdateStatus (); }
// gets the database id for the specified playlist string getFeedID(Feed feed) { long feed_id = -1; string sql = "SELECT id FROM feed WHERE url='" + parseSql (feed.Url) + "'"; dbcon.Open (); IDbCommand dbcmd = dbcon.CreateCommand (); dbcmd.CommandText = sql; IDataReader reader = dbcmd.ExecuteReader (); if (reader.Read ()) feed_id = reader.GetInt64 (0); reader.Close (); reader = null; dbcmd.Dispose (); dbcmd = null; dbcon.Close (); return feed_id.ToString (); }
/// <summary> /// Updates the specified news feed in the database. /// </summary> public void UpdateFeed(Feed feed) { string sql = "UPDATE feed SET etag='" + parseSql (feed.ETag) + "', last_modified='" + parseSql (feed.LastModified) + "', autorefresh='" + feed.AutoRefresh.ToString () + "' WHERE url='" + parseSql (feed.Url) + "'"; executeSql (sql); }