Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improved new feed code

  • Loading branch information...
commit 4187daad866d6393f5d96051e146d19b5c524ac4 1 parent 976f3dc
@seuffert authored
Showing with 75 additions and 45 deletions.
  1. +3 −0  XBSlink/Form1.Designer.cs
  2. +72 −45 XBSlink/Form1.cs
View
3  XBSlink/Form1.Designer.cs
@@ -921,6 +921,7 @@ private void InitializeComponent()
this.checkBox_switchToNewsTab.Size = new System.Drawing.Size(236, 17);
this.checkBox_switchToNewsTab.TabIndex = 3;
this.checkBox_switchToNewsTab.Text = "switch to news tab if new news are available";
+ this.toolTip1.SetToolTip(this.checkBox_switchToNewsTab, "set the news feed tab active if updated news are available.");
this.checkBox_switchToNewsTab.UseVisualStyleBackColor = true;
//
// label7
@@ -952,6 +953,8 @@ private void InitializeComponent()
this.textBox_newsFeedUri.Size = new System.Drawing.Size(314, 20);
this.textBox_newsFeedUri.TabIndex = 0;
this.textBox_newsFeedUri.Text = "http://www.secudb.de/~seuffert/xbslink/feed";
+ this.textBox_newsFeedUri.TextChanged += new System.EventHandler(this.textBox_newsFeedUri_TextChanged);
+ this.textBox_newsFeedUri.Leave += new System.EventHandler(this.textBox_newsFeedUri_Leave);
//
// groupBox_usersettings
//
View
117 XBSlink/Form1.cs
@@ -1741,59 +1741,76 @@ private void checkBox_preventSystemStandby_CheckedChanged(object sender, EventAr
private void loadNewsFeed( String url )
{
- richTextBox_newsFeed.Clear();
-
- string result = null;
- WebClient client = new WebClient();
- client.Proxy = null;
try
{
- result = client.DownloadString(url);
- }
- catch (WebException wex)
- {
- richTextBox_newsFeed.AppendText("Error loading news feed: " + wex.Message);
- return;
- }
-
- FontFamily myFontFamily = new FontFamily("Arial");
- Font font_head = new Font(myFontFamily, 14, FontStyle.Bold, GraphicsUnit.Pixel);
- Font font_summary = new Font(myFontFamily, 10, FontStyle.Regular, GraphicsUnit.Pixel);
- SyndicationFeed feed;
- try
- {
- feed = SyndicationFeed.Load(XmlReader.Create(new System.IO.StringReader(result)));
- }
- catch (Exception ex)
- {
- richTextBox_newsFeed.AppendText("Error parsing news feed");
- return;
- }
+ richTextBox_newsFeed.Clear();
- String first_id = null;
- foreach (SyndicationItem item in feed.Items)
- {
- if (first_id == null)
- first_id = item.Id;
- String date = item.PublishDate.Month + "-" + item.PublishDate.Day;
- richTextBox_newsFeed.SelectionFont = font_head;
- richTextBox_newsFeed.SelectionColor = Color.DarkRed;
- richTextBox_newsFeed.AppendText(date + " " + item.Title.Text + Environment.NewLine);
+ string result = null;
+ WebClient client = new WebClient();
+ client.Proxy = null;
+ try
+ {
+ result = client.DownloadString(url);
+ }
+ catch (WebException wex)
+ {
+ richTextBox_newsFeed.AppendText("Error loading news feed: " + wex.Message);
+ return;
+ }
+ if (result == null || result.Length == 0)
+ {
+ richTextBox_newsFeed.AppendText("Error loading news feed. no information returned.");
+ return;
+ }
- richTextBox_newsFeed.SelectionFont = font_summary;
- richTextBox_newsFeed.SelectionColor = Color.Black;
- richTextBox_newsFeed.AppendText(item.Summary.Text + Environment.NewLine);
+ FontFamily myFontFamily = new FontFamily("Arial");
+ Font font_head = new Font(myFontFamily, 14, FontStyle.Bold, GraphicsUnit.Pixel);
+ Font font_summary = new Font(myFontFamily, 10, FontStyle.Regular, GraphicsUnit.Pixel);
- richTextBox_newsFeed.AppendText(item.Links[0].Uri.ToString() + Environment.NewLine);
- richTextBox_newsFeed.AppendText(Environment.NewLine);
- }
+ SyndicationFeed feed;
+ try
+ {
+ feed = SyndicationFeed.Load(XmlReader.Create(new System.IO.StringReader(result)));
+ }
+ catch (Exception ex)
+ {
+ richTextBox_newsFeed.AppendText("Error parsing news feed");
+ return;
+ }
- if ((first_id != xbs_settings.settings.REG_NEWS_FEED_NEWEST_ID) && checkBox_switchToNewsTab.Checked)
+ String first_id = null;
+ foreach (SyndicationItem item in feed.Items)
+ {
+ if (first_id == null)
+ first_id = item.Id;
+ String date = item.PublishDate.Month + "-" + item.PublishDate.Day;
+ richTextBox_newsFeed.SelectionFont = font_head;
+ richTextBox_newsFeed.SelectionColor = Color.DarkRed;
+ richTextBox_newsFeed.AppendText(date + " " + item.Title.Text + Environment.NewLine);
+
+ richTextBox_newsFeed.SelectionFont = font_summary;
+ richTextBox_newsFeed.SelectionColor = Color.Black;
+ richTextBox_newsFeed.AppendText(item.Summary.Text + Environment.NewLine);
+
+ if (item.Links.Count > 0)
+ richTextBox_newsFeed.AppendText(item.Links[0].Uri.ToString() + Environment.NewLine);
+ richTextBox_newsFeed.AppendText(Environment.NewLine);
+ }
+
+ richTextBox_newsFeed.SelectionStart = 0;
+ richTextBox_newsFeed.ScrollToCaret();
+
+ if ((first_id != xbs_settings.settings.REG_NEWS_FEED_NEWEST_ID) && checkBox_switchToNewsTab.Checked)
+ {
+ tabControl1.SelectedTab = tabPage_newsFeed;
+ xbs_settings.settings.REG_NEWS_FEED_NEWEST_ID = first_id;
+ xbs_settings.settings.Save();
+ }
+ }
+ catch (Exception ex)
{
- tabControl1.SelectedTab = tabPage_newsFeed;
- xbs_settings.settings.REG_NEWS_FEED_NEWEST_ID = first_id;
- xbs_settings.settings.Save();
+ xbs_messages.addInfoMessage("!!ERROR!! could not initialize news feed: "+ex.Message, xbs_message_sender.GENERAL, xbs_message_type.ERROR);
}
}
@@ -1819,5 +1836,15 @@ private void checkBox_showNewsFeed_CheckedChanged(object sender, EventArgs e)
tabControl1.TabPages.Remove(tabPage_newsFeed);
}
}
+
+ private void textBox_newsFeedUri_TextChanged(object sender, EventArgs e)
+ {
+ }
+
+ private void textBox_newsFeedUri_Leave(object sender, EventArgs e)
+ {
+ if (textBox_newsFeedUri.Text.Length == 0)
+ textBox_newsFeedUri.Text = Settings.Default.REG_NEWS_FEED_URI;
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.