Skip to content

Commit

Permalink
Move default settings into constants
Browse files Browse the repository at this point in the history
  • Loading branch information
cwc committed Nov 3, 2015
1 parent 5b1bf4e commit ddf88a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions PreferencesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public partial class PreferencesForm : Form
public const string CLOSE_ON_ACTIVITY_PREF = "CloseOnActivity";
public const string INTERVAL_PREF = "RotationInterval";

public const string URL_PREF_DEFAULT = "https://www.google.com/trends/hottrends/visualize?nrow=5&ncol=5 https://screensaver.twingly.com/ http://map.ipviking.com/";
public const string CLOSE_ON_ACTIVITY_PREF_DEFAULT = "True";
public const string INTERVAL_PREF_DEFAULT = "30";

public PreferencesForm()
{
InitializeComponent();
Expand All @@ -24,9 +28,9 @@ public PreferencesForm()
private void PreferencesForm_Load(object sender, EventArgs e)
{
RegistryKey reg = Registry.CurrentUser.CreateSubKey(Program.KEY);
tbUrl.Text = (string)reg.GetValue(URL_PREF, "http://www.polidea.pl");
cbCloseOnActivity.Checked = Boolean.Parse((string)reg.GetValue(CLOSE_ON_ACTIVITY_PREF, "True"));
nudRotationInterval.Value = int.Parse((string)reg.GetValue(INTERVAL_PREF, "30"));
tbUrl.Text = (string)reg.GetValue(URL_PREF, URL_PREF_DEFAULT);
cbCloseOnActivity.Checked = Boolean.Parse((string)reg.GetValue(CLOSE_ON_ACTIVITY_PREF, CLOSE_ON_ACTIVITY_PREF_DEFAULT));
nudRotationInterval.Value = int.Parse((string)reg.GetValue(INTERVAL_PREF, INTERVAL_PREF_DEFAULT));
reg.Close();
}

Expand Down
8 changes: 5 additions & 3 deletions ScreensaverForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public string[] Urls
get
{
RegistryKey reg = Registry.CurrentUser.CreateSubKey(Program.KEY);
var urls = ((string)reg.GetValue(PreferencesForm.URL_PREF, "http://www.polidea.pl")).Split(' ');
var urls = ((string)reg.GetValue(PreferencesForm.URL_PREF, PreferencesForm.URL_PREF_DEFAULT)).Split(' ');
reg.Close();

return urls;
Expand All @@ -50,7 +50,7 @@ private void ScreensaverForm_Load(object sender, EventArgs e)

currentSiteIndex = 0;
timer = new Timer();
timer.Interval = int.Parse((string)reg.GetValue(PreferencesForm.INTERVAL_PREF, "30")) * 1000;
timer.Interval = int.Parse((string)reg.GetValue(PreferencesForm.INTERVAL_PREF, PreferencesForm.INTERVAL_PREF_DEFAULT)) * 1000;
timer.Tick += (s, ee) => RotateSite();
timer.Start();
}
Expand Down Expand Up @@ -96,7 +96,7 @@ private void HandleUserActivity()

RegistryKey reg = Registry.CurrentUser.CreateSubKey(Program.KEY);

if (Boolean.Parse((string)reg.GetValue(PreferencesForm.CLOSE_ON_ACTIVITY_PREF, "True")))
if (Boolean.Parse((string)reg.GetValue(PreferencesForm.CLOSE_ON_ACTIVITY_PREF, PreferencesForm.CLOSE_ON_ACTIVITY_PREF_DEFAULT)))
{
Close();
}
Expand All @@ -105,6 +105,8 @@ private void HandleUserActivity()
closeButton.Visible = true;
Cursor.Show();
}

reg.Close();
}

private void closeButton_Click(object sender, EventArgs e)
Expand Down

0 comments on commit ddf88a3

Please sign in to comment.