mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-01-13 17:22:48 -05:00
Add setting for default user agent
This commit is contained in:
@@ -9,6 +9,14 @@
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="300">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="15" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="5" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -17,6 +25,34 @@
|
||||
Name="StartWithWindowsCheckBox"
|
||||
VerticalAlignment="Top"
|
||||
VerticalContentAlignment="Center"
|
||||
Margin="0,5"
|
||||
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>
|
||||
</options:OptionsPanelBase>
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
using System.Windows;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
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
|
||||
{
|
||||
@@ -17,6 +27,10 @@ namespace FeedCenter.Options
|
||||
var settings = Properties.Settings.Default;
|
||||
|
||||
StartWithWindowsCheckBox.IsChecked = settings.StartWithWindows;
|
||||
|
||||
LoadBrowserComboBox(BrowserComboBox, settings.Browser);
|
||||
|
||||
LoadUserAgentComboBox(UserAgentComboBox, settings.DefaultUserAgent);
|
||||
}
|
||||
|
||||
public override bool ValidatePanel()
|
||||
@@ -28,12 +42,91 @@ namespace FeedCenter.Options
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace FeedCenter.Options
|
||||
_optionPanels.Add(new GeneralOptionsPanel());
|
||||
_optionPanels.Add(new DisplayOptionsPanel());
|
||||
_optionPanels.Add(new FeedsOptionsPanel());
|
||||
_optionPanels.Add(new ReadingOptionsPanel());
|
||||
_optionPanels.Add(new UpdateOptionsPanel());
|
||||
_optionPanels.Add(new AboutOptionsPanel());
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user