176 lines
6.5 KiB
C#
176 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
|
|
namespace RadioDJViewer
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
private string outputFolderPath = string.Empty;
|
|
private string mainImagesFolderPath = string.Empty;
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
this.buttonSelectOutputFolder.Click += ButtonSelectOutputFolder_Click;
|
|
this.button6.Click += ButtonSelectMainImagesFolder_Click;
|
|
this.button3.Click += button3_Click;
|
|
this.button1.Click += button1_Click;
|
|
this.button4.Click += button4_Click;
|
|
this.button5.Click += button5_Click;
|
|
this.button2.Click += button2_Click;
|
|
// Populate profile list on open
|
|
LoadProfileList();
|
|
// Auto-load first profile's data into fields if available
|
|
LoadSelectedProfileFields();
|
|
this.comboBox1.SelectedIndexChanged += ComboBox1_SelectedIndexChanged;
|
|
}
|
|
|
|
private void LoadProfileList()
|
|
{
|
|
comboBox1.Items.Clear();
|
|
var names = ProfileStorage.GetProfileNames();
|
|
comboBox1.Items.AddRange(names.ToArray());
|
|
if (comboBox1.Items.Count > 0)
|
|
comboBox1.SelectedIndex = 0;
|
|
}
|
|
|
|
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
LoadSelectedProfileFields();
|
|
}
|
|
|
|
private void LoadSelectedProfileFields()
|
|
{
|
|
if (comboBox1.SelectedItem != null)
|
|
{
|
|
var profile = ProfileStorage.LoadProfile(comboBox1.SelectedItem.ToString());
|
|
if (profile != null)
|
|
{
|
|
textBox6.Text = profile.Name;
|
|
textBox2.Text = profile.IP;
|
|
textBox3.Text = profile.Port;
|
|
textBox4.Text = profile.Password;
|
|
outputFolderPath = profile.OutputFolder;
|
|
mainImagesFolderPath = profile.MainImagesFolder;
|
|
labelOutputFolderPath.Text = outputFolderPath;
|
|
label6.Text = mainImagesFolderPath;
|
|
textBox5.Text = profile.OutputImageName;
|
|
textBox1.Text = profile.UrlFormat;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ButtonSelectOutputFolder_Click(object sender, EventArgs e)
|
|
{
|
|
using (var dialog = new FolderBrowserDialog())
|
|
{
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
outputFolderPath = dialog.SelectedPath;
|
|
labelOutputFolderPath.Text = outputFolderPath;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ButtonSelectMainImagesFolder_Click(object sender, EventArgs e)
|
|
{
|
|
using (var dialog = new FolderBrowserDialog())
|
|
{
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
mainImagesFolderPath = dialog.SelectedPath;
|
|
label6.Text = mainImagesFolderPath;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
// Save Profile (Save Profile button)
|
|
if (string.IsNullOrWhiteSpace(textBox6.Text))
|
|
{
|
|
MessageBox.Show("Profile name is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
var profile = new Profile
|
|
{
|
|
Name = textBox6.Text,
|
|
IP = textBox2.Text,
|
|
Port = textBox3.Text,
|
|
Password = textBox4.Text,
|
|
OutputFolder = outputFolderPath,
|
|
MainImagesFolder = mainImagesFolderPath,
|
|
OutputImageName = textBox5.Text,
|
|
UrlFormat = textBox1.Text
|
|
};
|
|
ProfileStorage.SaveProfile(profile);
|
|
// Refresh profile list
|
|
comboBox1.Items.Clear();
|
|
var names = ProfileStorage.GetProfileNames();
|
|
comboBox1.Items.AddRange(names.ToArray());
|
|
MessageBox.Show("Profile saved successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
// Remove Profile (Remove Profile button)
|
|
if (comboBox1.SelectedItem != null)
|
|
{
|
|
ProfileStorage.DeleteProfile(comboBox1.SelectedItem.ToString());
|
|
comboBox1.Items.Clear();
|
|
var names = ProfileStorage.GetProfileNames();
|
|
comboBox1.Items.AddRange(names.ToArray());
|
|
}
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
// Load Profile (Load Profile button)
|
|
if (comboBox1.SelectedItem != null)
|
|
{
|
|
var profile = ProfileStorage.LoadProfile(comboBox1.SelectedItem.ToString());
|
|
if (profile != null)
|
|
{
|
|
textBox6.Text = profile.Name;
|
|
textBox2.Text = profile.IP;
|
|
textBox3.Text = profile.Port;
|
|
textBox4.Text = profile.Password;
|
|
outputFolderPath = profile.OutputFolder;
|
|
mainImagesFolderPath = profile.MainImagesFolder;
|
|
labelOutputFolderPath.Text = outputFolderPath;
|
|
label6.Text = mainImagesFolderPath;
|
|
textBox5.Text = profile.OutputImageName;
|
|
textBox1.Text = profile.UrlFormat;
|
|
Main mainForm = Application.OpenForms["Main"] as Main;
|
|
if (mainForm != null)
|
|
{
|
|
mainForm.LoadProfile(profile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
// Save (bottom Save button) - save all fields to the currently selected or new profile
|
|
button3_Click(sender, e); // Reuse Save Profile logic
|
|
if (!string.IsNullOrWhiteSpace(textBox6.Text))
|
|
this.Close();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
// Cancel (bottom Cancel button) - close the settings window without saving
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|