Work done so far
This commit is contained in:
+155
-27
@@ -13,6 +13,7 @@ namespace PainoBar_Helper
|
||||
_profileManager = profileManager;
|
||||
_currentSettings = new ProfileSettings
|
||||
{
|
||||
PianobarPath = currentSettings.PianobarPath,
|
||||
EnableTextFile = currentSettings.EnableTextFile,
|
||||
TextFilePath = currentSettings.TextFilePath,
|
||||
EnableWebServer = currentSettings.EnableWebServer,
|
||||
@@ -22,7 +23,8 @@ namespace PainoBar_Helper
|
||||
OverrideCredentials = currentSettings.OverrideCredentials,
|
||||
ConfigFilePath = currentSettings.ConfigFilePath,
|
||||
PianobarUser = currentSettings.PianobarUser,
|
||||
PianobarPassword = currentSettings.PianobarPassword
|
||||
PianobarPassword = currentSettings.PianobarPassword,
|
||||
KillProcessOnDisconnect = currentSettings.KillProcessOnDisconnect
|
||||
};
|
||||
|
||||
_currentProfileName = profileManager.ActiveProfileName;
|
||||
@@ -43,6 +45,8 @@ namespace PainoBar_Helper
|
||||
if (profiles_combo_box_selector == null)
|
||||
return;
|
||||
|
||||
string? currentText = profiles_combo_box_selector.Text;
|
||||
|
||||
profiles_combo_box_selector.Items.Clear();
|
||||
foreach (var profile in _profileManager.Profiles)
|
||||
{
|
||||
@@ -51,10 +55,20 @@ namespace PainoBar_Helper
|
||||
|
||||
if (!string.IsNullOrEmpty(_currentProfileName))
|
||||
profiles_combo_box_selector.SelectedItem = _currentProfileName;
|
||||
else if (!string.IsNullOrEmpty(currentText))
|
||||
profiles_combo_box_selector.Text = currentText;
|
||||
}
|
||||
|
||||
private void LoadSettingsToControls()
|
||||
{
|
||||
// Update profile name text box with current profile name
|
||||
if (profile_name_text_box != null && !string.IsNullOrEmpty(_currentProfileName))
|
||||
profile_name_text_box.Text = _currentProfileName;
|
||||
|
||||
// Pianobar executable path
|
||||
if (pianobar_path_text_box != null)
|
||||
pianobar_path_text_box.Text = _currentSettings.PianobarPath;
|
||||
|
||||
// Output Settings (Tab 1)
|
||||
if (obs_text_output_check_box != null)
|
||||
obs_text_output_check_box.Checked = _currentSettings.EnableTextFile;
|
||||
@@ -89,10 +103,17 @@ namespace PainoBar_Helper
|
||||
|
||||
if (txtPianobarPass != null)
|
||||
txtPianobarPass.Text = _currentSettings.PianobarPassword;
|
||||
|
||||
if (chkkillpro != null)
|
||||
chkkillpro.Checked = _currentSettings.KillProcessOnDisconnect;
|
||||
}
|
||||
|
||||
private void SaveSettingsFromControls()
|
||||
{
|
||||
// Pianobar Path
|
||||
if (pianobar_path_text_box != null)
|
||||
_currentSettings.PianobarPath = pianobar_path_text_box.Text;
|
||||
|
||||
// Output Settings
|
||||
if (obs_text_output_check_box != null)
|
||||
_currentSettings.EnableTextFile = obs_text_output_check_box.Checked;
|
||||
@@ -124,6 +145,9 @@ namespace PainoBar_Helper
|
||||
|
||||
if (txtPianobarPass != null)
|
||||
_currentSettings.PianobarPassword = txtPianobarPass.Text;
|
||||
|
||||
if (chkkillpro != null)
|
||||
_currentSettings.KillProcessOnDisconnect = chkkillpro.Checked;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -133,46 +157,86 @@ namespace PainoBar_Helper
|
||||
// Wire this to profiles_combo_box_selector.SelectedIndexChanged in the Designer
|
||||
public void profiles_combo_box_selector_SelectedIndexChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is not ComboBox cmb || cmb.SelectedItem is not string profileName)
|
||||
if (sender is not ComboBox cmb)
|
||||
return;
|
||||
|
||||
var profile = _profileManager.Profiles.FirstOrDefault(p => p.Name == profileName);
|
||||
if (profile != null)
|
||||
// Update profile name text box when selection changes
|
||||
if (profile_name_text_box != null)
|
||||
profile_name_text_box.Text = cmb.Text;
|
||||
|
||||
// If selecting an existing profile, load its settings
|
||||
if (cmb.SelectedItem is string profileName)
|
||||
{
|
||||
_currentProfileName = profileName;
|
||||
_currentSettings = new ProfileSettings
|
||||
var profile = _profileManager.Profiles.FirstOrDefault(p => p.Name == profileName);
|
||||
if (profile != null)
|
||||
{
|
||||
EnableTextFile = profile.Settings.EnableTextFile,
|
||||
TextFilePath = profile.Settings.TextFilePath,
|
||||
EnableWebServer = profile.Settings.EnableWebServer,
|
||||
WebServerPort = profile.Settings.WebServerPort,
|
||||
EnableToastNotifications = profile.Settings.EnableToastNotifications,
|
||||
EnableSMTC = profile.Settings.EnableSMTC,
|
||||
OverrideCredentials = profile.Settings.OverrideCredentials,
|
||||
ConfigFilePath = profile.Settings.ConfigFilePath,
|
||||
PianobarUser = profile.Settings.PianobarUser,
|
||||
PianobarPassword = profile.Settings.PianobarPassword
|
||||
};
|
||||
LoadSettingsToControls();
|
||||
_currentProfileName = profileName;
|
||||
_currentSettings = new ProfileSettings
|
||||
{
|
||||
PianobarPath = profile.Settings.PianobarPath,
|
||||
EnableTextFile = profile.Settings.EnableTextFile,
|
||||
TextFilePath = profile.Settings.TextFilePath,
|
||||
EnableWebServer = profile.Settings.EnableWebServer,
|
||||
WebServerPort = profile.Settings.WebServerPort,
|
||||
EnableToastNotifications = profile.Settings.EnableToastNotifications,
|
||||
EnableSMTC = profile.Settings.EnableSMTC,
|
||||
OverrideCredentials = profile.Settings.OverrideCredentials,
|
||||
ConfigFilePath = profile.Settings.ConfigFilePath,
|
||||
PianobarUser = profile.Settings.PianobarUser,
|
||||
PianobarPassword = profile.Settings.PianobarPassword,
|
||||
KillProcessOnDisconnect = profile.Settings.KillProcessOnDisconnect
|
||||
};
|
||||
LoadSettingsToControls();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wire this to profiles_combo_box_selector.TextChanged in the Designer
|
||||
public void profiles_combo_box_selector_TextChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is not ComboBox cmb)
|
||||
return;
|
||||
|
||||
// Keep profile name text box in sync with combo box text
|
||||
if (profile_name_text_box != null)
|
||||
profile_name_text_box.Text = cmb.Text;
|
||||
}
|
||||
|
||||
// Wire this to new_profile_button.Click in the Designer
|
||||
public void new_profile_button_Click(object? sender, EventArgs e)
|
||||
{
|
||||
string? profileName = PromptForProfileName("New Profile", "Enter profile name:");
|
||||
// Get the profile name from the combo box text
|
||||
string? profileName = profiles_combo_box_selector?.Text?.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(profileName))
|
||||
{
|
||||
MessageBox.Show("Please enter a profile name in the dropdown box.", "No Profile Name",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if profile already exists
|
||||
if (_profileManager.Profiles.Any(p => p.Name.Equals(profileName, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
MessageBox.Show($"Profile '{profileName}' already exists. Please choose a different name.", "Profile Exists",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var newSettings = new ProfileSettings();
|
||||
_profileManager.CreateProfile(profileName, newSettings);
|
||||
// Create new profile with current settings
|
||||
SaveSettingsFromControls();
|
||||
_profileManager.CreateProfile(profileName, _currentSettings);
|
||||
_currentProfileName = profileName;
|
||||
|
||||
LoadProfileList();
|
||||
if (profiles_combo_box_selector != null)
|
||||
profiles_combo_box_selector.SelectedItem = profileName;
|
||||
|
||||
if (profile_name_text_box != null)
|
||||
profile_name_text_box.Text = profileName;
|
||||
|
||||
MessageBox.Show($"Profile '{profileName}' created successfully.", "Profile Created",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
@@ -186,20 +250,32 @@ namespace PainoBar_Helper
|
||||
// Wire this to delete_profile_button.Click in the Designer
|
||||
public void delete_profile_button_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_currentProfileName))
|
||||
// Get the profile name from either the combo box or the profile name text box
|
||||
string? profileName = profiles_combo_box_selector?.Text?.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(profileName))
|
||||
{
|
||||
MessageBox.Show("No profile selected.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show($"Are you sure you want to delete profile '{_currentProfileName}'?",
|
||||
// Check if profile exists
|
||||
if (!_profileManager.Profiles.Any(p => p.Name.Equals(profileName, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
MessageBox.Show($"Profile '{profileName}' does not exist.", "Profile Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show($"Are you sure you want to delete profile '{profileName}'?",
|
||||
"Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
_profileManager.DeleteProfile(_currentProfileName);
|
||||
_profileManager.DeleteProfile(profileName);
|
||||
|
||||
// Reset to active profile or clear
|
||||
_currentProfileName = _profileManager.ActiveProfileName;
|
||||
LoadProfileList();
|
||||
|
||||
@@ -209,8 +285,18 @@ namespace PainoBar_Helper
|
||||
_currentSettings = activeProfile.Settings;
|
||||
LoadSettingsToControls();
|
||||
}
|
||||
else
|
||||
{
|
||||
// No profiles left, clear the form
|
||||
_currentSettings = new ProfileSettings();
|
||||
LoadSettingsToControls();
|
||||
if (profiles_combo_box_selector != null)
|
||||
profiles_combo_box_selector.Text = string.Empty;
|
||||
if (profile_name_text_box != null)
|
||||
profile_name_text_box.Text = string.Empty;
|
||||
}
|
||||
|
||||
MessageBox.Show("Profile deleted successfully.", "Profile Deleted",
|
||||
MessageBox.Show($"Profile '{profileName}' deleted successfully.", "Profile Deleted",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -225,6 +311,24 @@ namespace PainoBar_Helper
|
||||
|
||||
#region File Browsing
|
||||
|
||||
// Wire this to painobar_exe_browse_button.Click in the Designer
|
||||
public void painobar_exe_browse_button_Click(object? sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "Executable Files (*.exe)|*.exe|All Files (*.*)|*.*",
|
||||
Title = "Select Pianobar Executable",
|
||||
FileName = "pianobar.exe",
|
||||
CheckFileExists = true
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (pianobar_path_text_box != null)
|
||||
pianobar_path_text_box.Text = dialog.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
// Wire this to output_folder_browse_button.Click in the Designer
|
||||
public void output_folder_browse_button_Click(object? sender, EventArgs e)
|
||||
{
|
||||
@@ -283,6 +387,9 @@ namespace PainoBar_Helper
|
||||
|
||||
if (txtPianobarPass != null)
|
||||
txtPianobarPass.Enabled = enabled;
|
||||
|
||||
if (chkkillpro != null)
|
||||
chkkillpro.Enabled = enabled;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -296,11 +403,32 @@ namespace PainoBar_Helper
|
||||
{
|
||||
SaveSettingsFromControls();
|
||||
|
||||
if (!string.IsNullOrEmpty(_currentProfileName))
|
||||
// Get the profile name from the text box (or combo box as fallback)
|
||||
string? profileName = profile_name_text_box?.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(profileName))
|
||||
profileName = profiles_combo_box_selector?.Text?.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(profileName))
|
||||
{
|
||||
_profileManager.UpdateProfile(_currentProfileName, _currentSettings);
|
||||
MessageBox.Show("Please enter a profile name before saving.", "No Profile Name",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update existing profile or create new one
|
||||
if (_profileManager.Profiles.Any(p => p.Name.Equals(profileName, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
_profileManager.UpdateProfile(profileName, _currentSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
_profileManager.CreateProfile(profileName, _currentSettings);
|
||||
}
|
||||
|
||||
// Set this profile as the active profile
|
||||
_profileManager.SetActiveProfile(profileName);
|
||||
_currentProfileName = profileName;
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user