Add setting for default user agent

This commit is contained in:
2017-08-15 16:57:24 -04:00
parent 80cd26b8c3
commit 952b65b387
12 changed files with 192 additions and 123 deletions

View File

@@ -268,9 +268,6 @@
<Compile Include="Options\OptionsWindow.xaml.cs"> <Compile Include="Options\OptionsWindow.xaml.cs">
<DependentUpon>OptionsWindow.xaml</DependentUpon> <DependentUpon>OptionsWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Options\ReadingOptionsPanel.xaml.cs">
<DependentUpon>ReadingOptionsPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Options\UpdateOptionsPanel.xaml.cs"> <Compile Include="Options\UpdateOptionsPanel.xaml.cs">
<DependentUpon>UpdateOptionsPanel.xaml</DependentUpon> <DependentUpon>UpdateOptionsPanel.xaml</DependentUpon>
</Compile> </Compile>
@@ -341,10 +338,6 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Options\ReadingOptionsPanel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Options\UpdateOptionsPanel.xaml"> <Page Include="Options\UpdateOptionsPanel.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@@ -142,7 +142,10 @@ namespace FeedCenter
webRequest.Credentials = new NetworkCredential(Username, Password, Domain); webRequest.Credentials = new NetworkCredential(Username, Password, Domain);
// Set a user agent string // Set a user agent string
webRequest.UserAgent = "FeedCenter " + UpdateCheck.LocalVersion; if (string.IsNullOrWhiteSpace(Properties.Settings.Default.DefaultUserAgent))
webRequest.UserAgent = "FeedCenter/" + UpdateCheck.LocalVersion;
else
webRequest.UserAgent = Properties.Settings.Default.DefaultUserAgent;
} }
// Set the default encoding // Set the default encoding

View File

@@ -9,6 +9,14 @@
d:DesignHeight="300" d:DesignHeight="300"
d:DesignWidth="300"> d:DesignWidth="300">
<Grid> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="15" />
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
@@ -17,6 +25,34 @@
Name="StartWithWindowsCheckBox" Name="StartWithWindowsCheckBox"
VerticalAlignment="Top" VerticalAlignment="Top"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
Margin="0,5"
Grid.ColumnSpan="2" /> Grid.ColumnSpan="2" />
<Label Content="{x:Static properties:Resources.defaultBrowserLabel}"
Target="{Binding ElementName=BrowserComboBox}"
Grid.Column="0"
Grid.Row="2"
Padding="0"
VerticalContentAlignment="Center"
Margin="0,0,5,0" />
<ComboBox Name="BrowserComboBox"
Grid.Row="2"
Grid.Column="1"
VerticalContentAlignment="Center">
<ComboBoxItem Content="{x:Static properties:Resources.DefaultBrowserCaption}"
Tag="" />
</ComboBox>
<Label Content="{x:Static properties:Resources.defaultUserAgentLabel}"
Target="{Binding ElementName=BrowserComboBox}"
Grid.Column="0"
Grid.Row="4"
Padding="0"
VerticalContentAlignment="Center"
Margin="0,0,5,0" />
<ComboBox Name="UserAgentComboBox"
Grid.Row="4"
Grid.Column="1"
VerticalContentAlignment="Center">
</ComboBox>
</Grid> </Grid>
</options:OptionsPanelBase> </options:OptionsPanelBase>

View File

@@ -1,5 +1,15 @@
using System.Windows; using System.Collections.Generic;
using System.Windows;
using Common.Wpf.Extensions; using Common.Wpf.Extensions;
using Common.Internet;
using System.Windows.Controls;
using System.Windows.Data;
internal class UserAgentItem
{
internal string Caption { get; set; }
internal string UserAgent { get; set; }
}
namespace FeedCenter.Options namespace FeedCenter.Options
{ {
@@ -17,6 +27,10 @@ namespace FeedCenter.Options
var settings = Properties.Settings.Default; var settings = Properties.Settings.Default;
StartWithWindowsCheckBox.IsChecked = settings.StartWithWindows; StartWithWindowsCheckBox.IsChecked = settings.StartWithWindows;
LoadBrowserComboBox(BrowserComboBox, settings.Browser);
LoadUserAgentComboBox(UserAgentComboBox, settings.DefaultUserAgent);
} }
public override bool ValidatePanel() public override bool ValidatePanel()
@@ -28,12 +42,91 @@ namespace FeedCenter.Options
{ {
var settings = Properties.Settings.Default; var settings = Properties.Settings.Default;
if (StartWithWindowsCheckBox.IsChecked.HasValue && settings.StartWithWindows != StartWithWindowsCheckBox.IsChecked.Value) if (StartWithWindowsCheckBox.IsChecked.HasValue &&
settings.StartWithWindows != StartWithWindowsCheckBox.IsChecked.Value)
settings.StartWithWindows = StartWithWindowsCheckBox.IsChecked.Value; settings.StartWithWindows = StartWithWindowsCheckBox.IsChecked.Value;
Application.Current.SetStartWithWindows(settings.StartWithWindows); Application.Current.SetStartWithWindows(settings.StartWithWindows);
settings.Browser = (string) ((ComboBoxItem) BrowserComboBox.SelectedItem).Tag;
settings.DefaultUserAgent = (string) ((ComboBoxItem) UserAgentComboBox.SelectedItem).Tag;
var expressions = this.GetBindingExpressions(new[] { UpdateSourceTrigger.Explicit });
this.UpdateAllSources(expressions);
} }
public override string CategoryName => Properties.Resources.optionCategoryGeneral; public override string CategoryName => Properties.Resources.optionCategoryGeneral;
private static void LoadBrowserComboBox(ComboBox comboBox, string selected)
{
comboBox.SelectedIndex = 0;
ComboBoxItem selectedItem = null;
var browsers = Browser.DetectInstalledBrowsers();
foreach (var browser in browsers)
{
var item = new ComboBoxItem { Content = browser.Value.Name, Tag = browser.Key };
comboBox.Items.Add(item);
if (browser.Key == selected)
selectedItem = item;
}
if (selectedItem != null)
comboBox.SelectedItem = selectedItem;
}
private static void LoadUserAgentComboBox(ComboBox comboBox, string selected)
{
comboBox.SelectedIndex = 0;
ComboBoxItem selectedItem = null;
var userAgents = GetUserAgents();
foreach (var userAgent in userAgents)
{
var item = new ComboBoxItem { Content = userAgent.Caption, Tag = userAgent.UserAgent };
comboBox.Items.Add(item);
if (userAgent.UserAgent == selected)
selectedItem = item;
}
if (selectedItem != null)
comboBox.SelectedItem = selectedItem;
}
private static List<UserAgentItem> GetUserAgents()
{
var userAgents = new List<UserAgentItem>
{
new UserAgentItem
{
Caption = Properties.Resources.DefaultUserAgentCaption,
UserAgent = string.Empty
},
new UserAgentItem
{
Caption = "Windows RSS Platform 2.0",
UserAgent = "Windows-RSS-Platform/2.0 (MSIE 9.0; Windows NT 6.1)"
},
new UserAgentItem
{
Caption = "Feedly 1.0",
UserAgent = "Feedly/1.0"
},
new UserAgentItem
{
Caption = "curl",
UserAgent = "curl/7.47.0"
}
};
return userAgents;
}
} }
} }

View File

@@ -36,7 +36,6 @@ namespace FeedCenter.Options
_optionPanels.Add(new GeneralOptionsPanel()); _optionPanels.Add(new GeneralOptionsPanel());
_optionPanels.Add(new DisplayOptionsPanel()); _optionPanels.Add(new DisplayOptionsPanel());
_optionPanels.Add(new FeedsOptionsPanel()); _optionPanels.Add(new FeedsOptionsPanel());
_optionPanels.Add(new ReadingOptionsPanel());
_optionPanels.Add(new UpdateOptionsPanel()); _optionPanels.Add(new UpdateOptionsPanel());
_optionPanels.Add(new AboutOptionsPanel()); _optionPanels.Add(new AboutOptionsPanel());
} }

View File

@@ -1,34 +0,0 @@
<options:OptionsPanelBase x:Class="FeedCenter.Options.ReadingOptionsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:options="clr-namespace:FeedCenter.Options"
xmlns:properties="clr-namespace:FeedCenter.Properties"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{x:Static properties:Resources.browserLabel}"
Target="{Binding ElementName=BrowserComboBox}"
Grid.Column="0"
Padding="0"
VerticalContentAlignment="Center"
Margin="0,0,5,0" />
<ComboBox Name="BrowserComboBox"
Grid.Row="0"
Grid.Column="1"
VerticalContentAlignment="Center">
<ComboBoxItem Content="{x:Static properties:Resources.DefaultBrowserCaption}"
Tag="" />
</ComboBox>
</Grid>
</options:OptionsPanelBase>

View File

@@ -1,64 +0,0 @@
using Common.Internet;
using Common.Wpf.Extensions;
using System.Windows.Controls;
using System.Windows.Data;
namespace FeedCenter.Options
{
public partial class ReadingOptionsPanel
{
public ReadingOptionsPanel()
{
InitializeComponent();
}
public override void LoadPanel(FeedCenterEntities database)
{
base.LoadPanel(database);
var settings = Properties.Settings.Default;
LoadBrowserComboBox(BrowserComboBox, settings.Browser);
}
public override bool ValidatePanel()
{
return true;
}
public override void SavePanel()
{
var settings = Properties.Settings.Default;
var browser = (string) ((ComboBoxItem) BrowserComboBox.SelectedItem).Tag;
settings.Browser = browser;
var expressions = this.GetBindingExpressions(new[] { UpdateSourceTrigger.Explicit });
this.UpdateAllSources(expressions);
}
public override string CategoryName => Properties.Resources.optionCategoryReading;
private static void LoadBrowserComboBox(ComboBox comboBox, string selected)
{
comboBox.SelectedIndex = 0;
ComboBoxItem selectedItem = null;
var browsers = Browser.DetectInstalledBrowsers();
foreach (var browser in browsers)
{
var item = new ComboBoxItem { Content = browser.Value.Name, Tag = browser.Key };
comboBox.Items.Add(item);
if (browser.Key == selected)
selectedItem = item;
}
if (selectedItem != null)
comboBox.SelectedItem = selectedItem;
}
}
}

View File

@@ -169,15 +169,6 @@ namespace FeedCenter.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to _Browser:.
/// </summary>
public static string browserLabel {
get {
return ResourceManager.GetString("browserLabel", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Edit Multiple Feeds. /// Looks up a localized string similar to Edit Multiple Feeds.
/// </summary> /// </summary>
@@ -470,7 +461,7 @@ namespace FeedCenter.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Default. /// Looks up a localized string similar to &lt; Windows Default &gt;.
/// </summary> /// </summary>
public static string DefaultBrowserCaption { public static string DefaultBrowserCaption {
get { get {
@@ -478,6 +469,33 @@ namespace FeedCenter.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Default _browser:.
/// </summary>
public static string defaultBrowserLabel {
get {
return ResourceManager.GetString("defaultBrowserLabel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Feed Center.
/// </summary>
public static string DefaultUserAgentCaption {
get {
return ResourceManager.GetString("DefaultUserAgentCaption", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Default _user agent:.
/// </summary>
public static string defaultUserAgentLabel {
get {
return ResourceManager.GetString("defaultUserAgentLabel", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Delete Category. /// Looks up a localized string similar to Delete Category.
/// </summary> /// </summary>

View File

@@ -346,11 +346,11 @@
<data name="registerAsDefaultFeedReaderCheckBox" xml:space="preserve"> <data name="registerAsDefaultFeedReaderCheckBox" xml:space="preserve">
<value>_Register as default feed reader</value> <value>_Register as default feed reader</value>
</data> </data>
<data name="browserLabel" xml:space="preserve"> <data name="defaultBrowserLabel" xml:space="preserve">
<value>_Browser:</value> <value>Default _browser:</value>
</data> </data>
<data name="DefaultBrowserCaption" xml:space="preserve"> <data name="DefaultBrowserCaption" xml:space="preserve">
<value>Default</value> <value>&lt; Windows Default &gt;</value>
</data> </data>
<data name="feedCategoryLabel" xml:space="preserve"> <data name="feedCategoryLabel" xml:space="preserve">
<value>_Category:</value> <value>_Category:</value>
@@ -523,4 +523,10 @@
<data name="CategoryFilterHeader" xml:space="preserve"> <data name="CategoryFilterHeader" xml:space="preserve">
<value>Category: {0}</value> <value>Category: {0}</value>
</data> </data>
<data name="DefaultUserAgentCaption" xml:space="preserve">
<value>Feed Center</value>
</data>
<data name="defaultUserAgentLabel" xml:space="preserve">
<value>Default _user agent:</value>
</data>
</root> </root>

View File

@@ -12,7 +12,7 @@ namespace FeedCenter.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -289,5 +289,18 @@ namespace FeedCenter.Properties {
this["LastCategoryID"] = value; this["LastCategoryID"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Configuration.SettingsProviderAttribute(typeof(Common.Settings.GenericSettingsProvider))]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string DefaultUserAgent {
get {
return ((string)(this["DefaultUserAgent"]));
}
set {
this["DefaultUserAgent"] = value;
}
}
} }
} }

View File

@@ -71,5 +71,8 @@
<Setting Name="LastCategoryID" Type="System.String" Scope="User"> <Setting Name="LastCategoryID" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
<Setting Name="DefaultUserAgent" Provider="Common.Settings.GenericSettingsProvider" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@@ -60,6 +60,9 @@
<setting name="LastCategoryID" serializeAs="String"> <setting name="LastCategoryID" serializeAs="String">
<value /> <value />
</setting> </setting>
<setting name="DefaultUserAgent" serializeAs="String">
<value />
</setting>
</FeedCenter.Properties.Settings> </FeedCenter.Properties.Settings>
</userSettings> </userSettings>
<applicationSettings> <applicationSettings>